Signalr 为什么不需要客户端响应

Signalr 为什么不需要客户端响应,signalr,signalr-hub,Signalr,Signalr Hub,源代码: 服务器发送心跳数据包,然后在不等待客户端响应的情况下将连接标记为活动 private void CheckTimeoutAndKeepAlive(ConnectionMetadata metadata) { if (RaiseTimeout(metadata)) { // If we're past the expiration time then just timeout the connection

源代码:

服务器发送心跳数据包,然后在不等待客户端响应的情况下将连接标记为活动

    private void CheckTimeoutAndKeepAlive(ConnectionMetadata metadata)
    {
        if (RaiseTimeout(metadata))
        {
            // If we're past the expiration time then just timeout the connection
            metadata.Connection.Timeout();
        }
        else
        {
            // The connection is still alive so we need to keep it alive with a server side "ping".
            // This is for scenarios where networking hardware (proxies, loadbalancers) get in the way
            // of us handling timeout's or disconnects gracefully
            if (RaiseKeepAlive(metadata))
            {
                Trace.TraceEvent(TraceEventType.Verbose, 0, "KeepAlive(" + metadata.Connection.ConnectionId + ")");

                // Ensure delegate continues to use the C# Compiler static delegate caching optimization.
                metadata.Connection.KeepAlive().Catch((ex, state) => OnKeepAliveError(ex, state), state: Trace, traceSource: Trace);
            }

            MarkConnection(metadata.Connection);
        }
    }
如何检测客户端已断开连接
客户端如何检测自身和服务器断开连接?

基本上取决于您的连接类型。(套接字、长轮询等)套接字提供TCP/UDP端口连接,并提供断开连接的通知


对于其他类型的连接,心跳或其他东西可以工作。信号器核心使用每秒一次的心跳。因此,SignalR Core会在一秒钟内检测到断开连接。

在此处共享您的代码,并就您的问题向我们提供更多详细信息