aparna bhogu

+ Follow
since Aug 03, 2014
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by aparna bhogu

I have a servlet which sends HTML5 server sent events to the jsp client. The servlet sends data to the client every one second. The jsp client instantiates a new eventsource and recieves the data. When the window is about to close, the jsp client closes eventsource at the "beforeunload" event (shown in the code below).

However, I have noticed that even after the client closes the eventsource and the browser exits, the server continues sending data. As far as the documentation on eventsource goes, using eventsource.close() is enough to stop client from reconnecting to the server and the server will stop sending any further push notifications.

Can any one please help me understand why the server does not stop sending push notifications even after eventsource.close() and the browser exit? Do I write any other piece of code to notify the server to stop sending data once client exits?

Thank you. Pasted below are the servlet (server ) code and the client code.

Here is the client code:
8 years ago
Code structure :

Server : Java Servlet
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?

Thank you for your help in advance.

8 years ago
I am using flot charts to display ecg signals. The requirement is that the chart background should look exactly like the ecg graph paper.

All the inner grey lines should be lined at precise points to draw perfect squares on the ecg sheet. However, there are some lines which are not spaced evenly (they are closer to each other), making the ecg graph background incorrect.

Here is what my code does :

MARKINGS : I have written a function to generate markings on x and y axis. Markings are the dark pink lines on the graph. These markings will be generated on x and y axis after 4 grey lines (which make up the smaller grey squares inside the bigger dark pink boxes). These seem to be drawn correctly.

TICKS: I have overridden Flot charts native tick generator by writing two functions which generate ticks on x and y axis . On x axis, each 40 ms represents one tick (one grey line) and on y axis 0.1 millivolt represents one grey line. Even though the functions generate correct arrays with correct values for ticks, the tick spacing on flot chart is not even. Some tick lines are more closely spaced which is incorrect.

Not all ticks are drawn incorrectly.However, the ones that have irregular spacing are significant in number and are visible on more careful inspection of the graph. For a start, the 4 th column and row of the graph has unevenly spaced tick lines. (On browser outside of jsfiddle, this becomes 3rd row and 3rd column ). These uneven ticks repeat randomly throughout the graph.

My code is as shown below. It has also been uploaded at Flot for ECG

I have also attached picture of the generated ECG Graph on my browser with irregularities marked with green boxes.

Has anyone gone through similar problem with flot charts while drawing tick lines? Am I using ticks incorrectly? Appreciate your help on this.


I have an application where I have data stored in a database. This needs to be rendered on a web page( a jsp page) as a real time graph. I am using Server Side Events for sending data from the database to the client page every second. On the client, I am using flot charts to render a real time graph.

I am receiving the data from server correctly every second. However, the flot chart is not displayed correctly. It just shows a single straight line going up and down. Here is the code:

The event.data received as per console.log is like this :


The graph shows a moving plot of a straight line which is incorrect. Also, the graph is not plotting from 0 of x-axis which is where the first datapoint starts.

Does this look like a concurrency issue. That is setupEventSource function has eventsource.onmessage which gets invoked every second and updates the serverDataPoints array. On the other hand, getRandomData gets invoked every few milliseconds to copy the server data and display it on the graph. Both these are present within $(function().

Thank you for your help in advance.
Thank you for pointing that out Bear Bibeault. Will keep that in mind.
8 years ago
Thank you K. Tsang and Ulf Dittmer. As you both rightly pointed out, I can make the JSP read the database directly rather than using the more complicated approaches I was thinking of. Thank you so much for pointing me in the right direction. Your responses have been most helpful.
8 years ago
The following programs exist: 1. I have a java application which accepts bio potential data every second or two and stores it in the database. This is a socket server which accepts this data from multiple clients and spawns a new thread for processing it to store in the db. 2. I have a jsp page on tomcat server which reads historic client data from database (stored by application 1) and displays it on the page.

The socket server program in 1.) above is not running inside of tomcat server.

The new requirement now is : Display all of the human data coming in live on the jsp page.

Now the problem: I will now need to pass the live data from socket server (which is stand alone) to the jsp which is running on a tomcat server.

Possible solutions:

APPROACH 1: Run the socket server in the tomcat instead of stand alone and store the frequently incoming data in a java object so the jsp can access this object every second and display it on a graph.

PROBLEM : The stand alone java application does not need to be included in a tomcat server except for the fact that the jsp needs access to the live data. Also, I have read that this is not the best way.

APPROACH 2: Expose the stand alone java application as a web service and communicate with the jsp using REST architecture.

PROBLEM : The complication of using this method is that it will not have the flexibility offered by websockets or server sent events (SSE) of auto updating the latest data. The jsp will have to keep polling for new data every one second which is also not a very good option.

I need suggestions on which is a better method for accomplishing my task. Or is there a third better way which I have completely missed.
8 years ago