Reputation: 123
I am connecting to Chrome Dev Tools from my C#/.NET app via Chrome Dev Tools protocol running on WebSocket. I discovered that if no message in sent/received for 30 sec, chrome kills the connection and I get this WebSocketException :
System.Net.WebSockets.WebSocketException:
The remote party closed the WebSocket connection without completing the close handshake.
Is there some way to dont let Chrome kill the connection ? Some elegant way to do keep-alive without manually sending blank messages every x seconds ? I am using standard WebSocket from System.Net.WebSockets and connect like this:
var socket = new ClientWebSocket();
socket.ConnectAsync(new Uri(target.webSocketDebuggerUrl),CancellationToken.None).Wait();
Thanks
Upvotes: 1
Views: 880
Reputation: 123
The standard .NET ClientWebSocket doesnt support manual pinging. However, it can be set via this property:
ClientWebSocket.ClientWebSocketOptions.KeepAliveInterval
The default value is 30 seconds, which is the same time after which the socket was getting closed. Setting this to some really high value made the problem dissapear. Unfortunately I am still not sure about the details of this problem and how does keep-alive work in .NET .
Upvotes: 1