我正在从我的C#/连接到Chrome开发工具。NET应用程序,通过运行在WebSocket上的Chrome开发工具协议。我发现,如果30秒内没有发送/接收消息,chrome会终止连接,我会得到这个WebSocketException:
System.Net.WebSockets.WebSocketException:
The remote party closed the WebSocket connection without completing the close handshake.
有没有办法不让Chrome破坏连接?不需要每隔x秒手动发送一条空白消息就能保持活力的优雅方法?我使用的是System中的标准WebSocket。网WebSockets和连接方式如下:
var socket = new ClientWebSocket();
socket.ConnectAsync(new Uri(target.webSocketDebuggerUrl),CancellationToken.None).Wait();
感谢
标准。NET ClientWebSocket不支持手动ping。但是,它可以通过以下属性设置:
ClientWebSocket.ClientWebSocketOptions.KeepAliveInterval
默认值为30秒,这与套接字关闭的时间相同。将其设置为某个非常高的值会使问题变得不明显。不幸的是,我仍然不确定这个问题的细节,以及如何保持活力。NET。