2012-03-20 23 views
5

どのようにSignalRがクライアントの切断を処理しますか?私は次のように述べていますか?SignalR:クライアントの切断

  • SignalRは、Javascriptのイベント処理を介してブラウザページのクローズ/リフレッシュを検出し、適切なパケットを(永続的な接続を通じて)サーバーに送信します。
  • SignalRは、ブラウザのクローズ/ネットワーク障害を検出しません(たぶんタイムアウトによってのみ)。

私は長いポーリング転送を目指しています。

私はthis questionを認識していますが、私にはそれを少しはっきりさせたいと思います。

答えて

9

ユーザーがページを更新すると、新しい接続として扱われます。切断がタイムアウトに基づいていることは間違いありません。

SignalR.Hubs.IConnectedSignalR.Hubs.IDisconnectを実装することで、ハブ内の接続/再接続と切断イベントを処理できます。

上記はSignalR 0.5.xです。 (現在v1.1.3デベロッパー用)the official documentationから

:SignalR 1.0で

public class ContosoChatHub : Hub 
{ 
    public override Task OnConnected() 
    { 
     // Add your own code here. 
     // For example: in a chat application, record the association between 
     // the current connection ID and user name, and mark the user as online. 
     // After the code in this method completes, the client is informed that 
     // the connection is established; for example, in a JavaScript client, 
     // the start().done callback is executed. 
     return base.OnConnected(); 
    } 

    public override Task OnDisconnected() 
    { 
     // Add your own code here. 
     // For example: in a chat application, mark the user as offline, 
     // delete the association between the current connection id and user name. 
     return base.OnDisconnected(); 
    } 

    public override Task OnReconnected() 
    { 
     // Add your own code here. 
     // For example: in a chat application, you might have marked the 
     // user as offline after a period of inactivity; in that case 
     // mark the user as online again. 
     return base.OnReconnected(); 
    } 
} 
6

、SignalR.Hubs.IConnectedとSignalR.Hubs.IDisconnectはもう実装されていない、と今では上だけオーバーライドですハブ自体:

public class Chat : Hub 
{ 
    public override Task OnConnected() 
    { 
     return base.OnConnected(); 
    } 

    public override Task OnDisconnected() 
    { 
     return base.OnDisconnected(); 
    } 

    public override Task OnReconnected() 
    { 
     return base.OnReconnected(); 
    } 
} 
関連する問題