Working with a WebSocket server using Microsoft.Web.WebSockets.WebSocketHandler where I'm keeping the connected clients in a WebSocketCollection. When the client loses its network connection, at the server the OnClose and OnError methods are not called. Additionally, looking at the specific client in the collection shows that its WebSocket.State is still described as connected. This is on IIS8.
Short of manually sending the client a message and looking for a response, is there another way to determine that the client has dropped of the network? Is there some IIS configuration I'm missing? Thanks.
Websocket client connections may drop due to intermittent network issue and when connections drop, messages will also be lost.
It has built-in means of detecting transmission errors or packet corruption and attempting retransmissions in those cases, but delivery can still fail. It guarantees that if the packet is not delivered, the caller will get an error so the caller can know. Since websocket is built on top of TCP, it has the same issue.
However, the connection between a client and your WebSocket app closes when no traffic is sent between them for 60 seconds.
I was able to solve my problem with two steps. First, I ran the following commands at the prompt to edit the IIS config.
cd \Windows\System32\inetsrv
appcmd unlock config /section:system.webServer/websocket
Then I updated my Web.config with the following.
<system.webServer>
<webSocket enabled="true" pingInterval="00:00:05" />
<system.webServer />
For IIS Express and VS projects, you have to edit "applicationhost.config" file and change overrideModeDefault="Allow"
<configSections>
<sectionGroup name="system.webServer">
...
<section name="webSocket" overrideModeDefault="Allow" />
</sectionGroup>
<configSections>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With