WebSocket Client Status Does Not Change to Network Loss

Working with a WebSocket server using Microsoft.Web.WebSockets.WebSocketHandler, where I store connected clients in a WebSocketCollection. When a client loses its network connection, the OnClose and OnError methods are not called on the server. In addition, looking at a specific client in the collection shows that its WebSocket.State is still described as related. This is on IIS8.

Failed to manually send a message to the client and find the answer, is there another way to determine if the client has abandoned the network? Is there some kind of IIS configuration I'm skipping? Thanks.

+7
c # websocket
source share
2 answers

I was able to solve my problem in two steps. First, I ran the following commands at the prompt to edit the IIS configuration.

cd \Windows\System32\inetsrv appcmd unlock config /section:system.webServer/websocket 

Then I updated my Web.config as follows.

 <system.webServer> <webSocket enabled="true" pingInterval="00:00:05" /> <system.webServer /> 
+14
source share

This is TCP: when you do not send or receive, how can you find out whether it is there or not?

If you kill a peer process or reboot it, this peer network stack will usually actively close TCP, so you will also immediately discover a lost WebSocket discovery. But if you just pull the plug onto a peer-to-peer network (network or network) or something else serious, TCP is not actively shutting down.

In the context of WebSocket, you can ping / pong at the WebSocket level (I don’t know if IIS supports this .. WS ping / pong heartbeating), or you can do beats at the application level by sending small WS messages.

-one
source share

All Articles