TAGS :Viewed: 13 - Published at: a few seconds ago

[ Client opens AJAX connection and waits for server to send an update ]

I have a Java server (no external libraries and does not use sun.net.httpserver package)

I would like to have the client open a connection with the server and wait until the server sends an update. The problem with this is that certain browsers (for example IE11) will use the AJAX socket to send a new request (for example GET / HTTP/1.1) and the problem with that is that it causes my server to crash. I could close the socket upon closing the webpage but then the client would have to open a new socket to send another HTTP request.

Is there an efficient way of doing this?

Edit: Another question... Is there a way to listen for changes on a socket's input stream using Java?

Answer 1


Since you are using long lived conenctions anyway, perhaps you should consider pushing the data from the server to the browser..

see the answers to this question, for much more information: Is there some way to PUSH data from web server to browser?