I have implemented a very basic server sent http streaming in my app
Client side code
var receiveRealTimePost=(function(){
var rtUrl= '${fetchRealTimePost}';
alert('Real time post function invoked');
var source = new EventSource(rtUrl);
source.onmessage=function(event){
document.getElementById("result").innerHTML+=event.data + "
";
};
})();
Server side
@RequestMapping(value="/getRealTimeServerPushUserPosts")
public SseEmitter getRealTimeServerPushUserPosts(){
SseEmitter sseEmitter = new SseEmitter();
try {
sseEmitter.send("Message #1");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return sseEmitter;
}
The connection is established. But on the UI why does the browser poll for the server every second. The alert is visible on the UI every second.
How does it make different from polling?
I saw the same thing happening with the twitter streaming REST API the browser polls the server every second.