0

I set up mini server using com.sun.net.httpserver as part of application which has ability to map files from hard disk and send them as response, just simple stuff for now (js, css, images, html).

My requirement is to talk to server with little overhead as possible, for now I am using jQuery ajax HEAD requests to send request back to server(I am parsing querystrings on server and do required action according to querystring)

But this is too slow for my needs, it takes 1-2 seconds(sometimes more) to recive request in my code where querystring gets parsed, and often connection gets clogged by too much requests, which I solved partially by timeouts and timers, but doing that only slows down whole thing.

Is there another, faster way to talk to server using js/jQuery?

Maybe something like reverse long polling? Is there such a thing? I assume establishing the connection each time adds lot of overhead, or am I wrong?

formatc
  • 4,261
  • 7
  • 43
  • 81
  • 1
    What *exactly* is taking 1-2 seconds? If that's the processing time needed on server side, you're hardly going to be able to find a faster way by switching the protocol over which they communicate, aren't you? – Pekka Jan 06 '13 at 13:42
  • @Pekka request is taking 1-2 secs without processing, the thing is I never used anything else for communication other then http requests, so I don't really know is there any other protocol that is faster. – formatc Jan 06 '13 at 13:45
  • 2
    sounds like a system architecture problem, 1-2 seconds is an eternity for majority of AJAX requests – charlietfl Jan 06 '13 at 13:48
  • Look into websockets, but I agree with Pekka and charlieftl. Are you sure it isn't a configuration problem in your webserver or the webserver isn't overloaded/ high IO contention? – Matt Jan 06 '13 at 13:59
  • @Matt thanks for suggestion, I'm positive about webserver config, could it could be due to client's WLAN (mobile device)? I just found [jwebsocket](http://jwebsocket.org/) which seems like a perfect solution for my problem. – formatc Jan 06 '13 at 14:08
  • @user1010609: Try pinging the server from the client. Note that ping is round trip time, so you should expect response times of 2-4 seconds if you're seeing the request taking 1-2 secs to be received by the server. Any less, and it's a software problem *somewhere*; client/ server. – Matt Jan 06 '13 at 14:12

1 Answers1

0

I tried jWebSocket and I got almost realtime communication between mobile device and jWebSocket server in Java application. It was little harder to set up due to lack of documentation, but speed got HUGE improvement.

formatc
  • 4,261
  • 7
  • 43
  • 81