Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
Server : JavaServlet Client : Simple JSP Communication : Server Sent Events every 1 second
Here is the problem.
My code needed the server to send updates every one second to the client as stated above. Hence, I added a while loop with a sleep of 1000 milliseconds in the servlet code as shown below. The following strange behavior is observed:
- While the server is sending updates to the client, and the client window closes by mistake, the server does not stop sending updates It continues sending the data.
- When the client is re-opened, it sends data much faster (almost double). For example, the server sends 60 seconds worth of updates (60 updates) in just 25-30 seconds. The server sends faster updates not only for this round of updates, but also for any subsequent updates.
On the other hand, when the servlet code is the default Server Sent Event code where server sends updates every 3 seconds and no while loop is involved, the server behaves as expected. Which is ::
- When the client window is closed while server is still sending updates, server stops sending the updates. The server resumes sending updates upon the client window being re-opened.
- Once, the window is re-opened, the rate which the data is being updated to the client is uniform : 3 seconds for a single update and 180 seconds for 60 updates.
The default Server Sent Events code for java where the update interval is 3 seconds is as shown below:
This server behavior is much unexpected. Am I writing the server side code wrong? I have looked around a lot and only found while loop method for modifying the server update interval. Is there any other method which I am missing? How can I overcome the above problem?
There is nothing wrong in your code. few things is there any mechanism to identify the client at the server end? that identifies the client and resume the data sending like session tracking? or identifying the client?
as you mentioned i haven't run into any problems with speed up thing.
here is server
here is my client
What a stench! Central nervous system shutting down. Save yourself tiny ad!
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth