I implemented the very easy and lazy method of requesting data from server via ajax in interval for real time affect.
But I want to opt for long polling/ comet technique as they encourage server to push data when there's one instead of client pulling constantly even when there's none.
I completely understand the way long polling and comet work. But I wish to see the coding part where server pushes when there's data to client.
How can for a request made by client long ago (long polling) can server push when there's data? I don't understand this part. Can someone show in coding please?
currently i check via ajax for new data in interval. Now, how can this be modified to implement long polling where server returns automatically when there's data without client asking for it?
(function notify(){
$.each(id, function(k, v){
jQuery.ajax({
method: "POST",
url: "/notification.php",
"data": v,
error: function() {
reject('error');
},
success: function(result) {
console.log(result.data);
}
});
})
setTimeout(function(){
notify();
}, 1000);
})()
Since this question marked as duplicate:
I said I fully understand the concept of long polling and comet. I'm here not to understand the concept but for the code that actually implement that concept!