2012-03-20 3 views
5

어떻게 SignalR이 클라이언트 단절을 처리합니까? 나는 다음과 같이 말하면 옳은가?SignalR : 클라이언트 단절

  • SignalR은 자바 스크립트 이벤트 처리를 통해 브라우저 페이지 닫기/새로 고침을 감지하고 (지속적인 연결을 통해) 적절한 패킷을 서버로 보냅니다.
  • SignalR은 브라우저 닫기/네트워크 오류를 감지하지 못합니다 (아마 시간 초과에 의해서만).

롱 폴링 전송을 목표로합니다.

나는 this question을 알고 있지만 조금 명확하게하고 싶습니다.

답변

9

사용자가 페이지를 새로 고치면 새 연결로 처리됩니다. 연결 끊기가 시간 초과를 기반으로 한 것이 맞습니다.

SignalR.Hubs.IConnectedSignalR.Hubs.IDisconnect을 구현하여 허브에서 연결/재 연결 및 연결 끊기 이벤트를 처리 할 수 ​​있습니다.

위의 내용은 SignalR 0.5.x를 참조했습니다.

이 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 더 이상 구현하고 있으며, 지금은 그냥 재정의입니다 : (현재 v1.1.3에 대한) the official documentation에서

허브 자체 :

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(); 
    } 
} 
관련 문제