0

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?

ThePyroEagle
  • 143
  • 12
  • "it causes my server to crash" then your sever is broken and should be fixed – Raedwald Jun 10 '15 at 12:02
  • @Raedwald The server isn't broken. It just expects an AJAX request and instead receives for example a GET, otherwise it works just fine. – ThePyroEagle Jun 10 '15 at 12:06
  • If input to your program can cause it to crash, your program is broken. If input over the network can cause your program to crash, it is vulnerable to a denial of service attack. – Raedwald Jun 10 '15 at 12:09
  • @Raedwald It doesn't matter because I've started redesigning the server because of how the old model worked. The new model will not contain the error because of a change on how it responds to new connections. – ThePyroEagle Jun 10 '15 at 12:35

1 Answers1

0

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?

Community
  • 1
  • 1
Henrik
  • 2,018
  • 15
  • 22
  • Thank you, this is exactly what I was looking for. I couldn't find it when I searched for it earlier (before asking the question). – ThePyroEagle Jun 10 '15 at 12:07