Say you have a long polling situation with a server and a client that subscribes to notifications using ajax recursively,
var subscribe = function () {
$.get('http://localhost:1234', function (data) {
// use the data
subscribe(); // send another request
});
}
On the server side, is there a reliable way to detect whether the client is actually there to receive requests -- in other words, that someone has the page open and is ready to receive pushed data? How do you handle the fact that clients might be offline but need to receive the data they missed upon logging back in?
I am currently implementing the server using reactive extensions for .NET based on the following link,
http://joseoncode.com/2011/06/17/event-driven-http-server-in-c-with-rx-and-httplistener/
using (var server = new HttpServer("http://localhost:1234/"))
{
//the listeners stream and subscription
var listeners = server
.Where(ctx => ctx.Request.HttpMethod == "GET")
//wait the next message to end the request
.Subscribe(ctx => subject.Take(1) .Subscribe(m => ctx.Respond(new StringResponse(m))));