0

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))));  
4

1 に答える 1

1

サーバー側で、クライアントが実際にリクエストを受信するためにそこにいるかどうか、つまり、誰かがページを開いて、プッシュされたデータを受信する準備ができているかどうかを検出する信頼できる方法はありますか?

信頼できる方法は、クライアントがサーバーからの通知を要求するのを待つことだと思います。

クライアント要求には、サブスクライブに成功したクライアント用にサーバーが保存する一意のクライアント ID が必要です。IDがそこにある場合は、彼が望むものを彼に与えてください。

クライアントがオフラインである可能性があるが、再ログイン時に見逃したデータを受信する必要があるという事実にどのように対処しますか?

クライアントはどのくらいオフラインのままで、どのくらいの頻度で新しい通知が作成されますか? クライアントがオフラインの状態が長すぎると、それまでに多くの通知を受け取ることになります。

または、クライアントがサブスクライブすると、インターネット接続が失われることを意味しているのかもしれません。次に、各クライアントには、クライアントが要求する前に通知が残るキューが必要になります。クライアントがオフラインの間、メッセージはキューに残ります。クライアントが長時間オフラインのままでストレージが大きくならないようにキュー内のメッセージをクリアするには、おそらく減衰時間が必要になるでしょう (redis などを使用すると仮定します)。

于 2011-10-26T12:38:33.417 に答える