1

I need to know the best (fastest) way to have a server (preferably a php based one, but a jsp/servlet one could be set up as well using google app engine) notify several java applets/applications that a change has occurred to the data.

The way i am picturing this to work will be very similar to that of the way i think an online java game (like Runescape) works
User 1: Changes data on server.
Server: returns success to User 1, notifies connected computers of change.
Connected Computer 1: processes change, returns success to server.
Connected Computer 2: processes change, returns success to server.
Connected Computer 3: processes change, returns success to server.
Connected Computer 4: processes change, returns success to server.

I am hoping to have this entire process complete in half a second, and not involve polling as there will be long durations of nothing, followed by a sudden moment where 4 events happen in succession.

Dustin Gamester
  • 792
  • 3
  • 8
  • 24
  • is this a browser client? See if this helps http://stackoverflow.com/questions/1285150/server-push-comet-in-google-app-engine-in-python – Aravind Yarram Dec 22 '10 at 20:32
  • @pangea yes, also it is digitally signed and running as a .jar so it runs with the same permissions as a standard java application. That link looks super useful, i'll check it out for sure. – Dustin Gamester Dec 22 '10 at 20:56

2 Answers2

1

If it has to be very fast and reliable, I wouldn't use a web server at all. I'd have a stand-alone server process and have the clients make direct TCP connections to it. More application are using a push from a web server, but I still find it very unreliable. Each client would need a thread that blocks on a socket read. They will get the data immediately when it arrives on the client system.

JOTN
  • 6,120
  • 2
  • 26
  • 31
  • After a bit of research i'd have to agree, nothing can compete with a socket connection. Thanks JOTN :) – Dustin Gamester Dec 29 '10 at 01:51
  • Agreed that if you have the flexibility to go this route that you will run into the least problems. Most java web servers limit the http server to 5 threads by default, this could be changed, but as JOTN pointed out for every client there would be a blocked thread, but you will also have blocked threads for each socket for a read, so its a trade off. – LINEMAN78 Jan 03 '11 at 23:57
1

Check out ICEPush for a Java implementation. I was able to find 2 posts that demonstrate how to implement similar in PHP. Both posts show an AJAX client, however you can reverse engineer it into simple HTTP requests in a java applet. Essentially all these engines are doing is having the client maintain a hanging HTTP request with the server, which is returned when the server has information for the clients. Basically, the client makes a request to the server and if the server doesn't have an event in the queue for that client it just holds on to the request and sleeps until there is a notification added to the queue or a timeout is reached at which point the server returns the request and the client parses it at which point it immediately makes another request to the server and the process starts over again. The timeout for ICEPush examples is just under 60s.

http://www.zeitoun.net/articles/comet_and_php/start
http://www.webreference.com/programming/javascript/rg28/index.html

LINEMAN78
  • 2,562
  • 16
  • 19