How does AJAX work with non-fixed-length HTTP responses?
April 23, 2009 8:47 AM Subscribe
AskMe Programming Squad: Need some help with AJAX and a slightly unusual method of communicating with a remote server.
posted by xbonesgt to Computers & Internet (7 answers total)
I've been told to investigate the replacing of our product's current Java-based client with a Web-based one. Most of it is pretty straightforward, but I need some help to determine whether our existing client's method of communication with the backend can be replicated with AJAX.
The existing client communicates with the backend via HTTP, using two different threads:
Client thread #1 opens up a socket and sends out a series of POST requests which tell the backend what to do. Each request gets replied to with a standard HTTP 200 (or 403 or whatever) response.
Client thread #2, upon program startup, opens up another socket and sends a single GET request. As events occur on the backend, chunks of data get sent to the client as part of the response to this request. The client doesn't wait for this data in the form of a completed HTTP response, but basically does a select() on the socket and waits until it receives anything.
Thread #1 is easy to implement on the client-side using AJAX. I've done that a few times before. My question is, is it possible to do the same thing for thread #2? I've only used AJAX to fetch HTML documents or DOM elements or whatever from a remote server; this sort of open-ended stuff would be new to me. Changing the communication scheme isn't possible for a couple of reasons; I need to work with what I have.
thanks in advance for any help!