Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebSocket Client's State Not Changing on Network Loss

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.

like image 249
Alan Avatar asked Oct 21 '13 19:10

Alan


People also ask

Can WebSocket messages get lost?

Websocket client connections may drop due to intermittent network issue and when connections drop, messages will also be lost.

Why WebSockets are not reliable?

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.

How long can WebSocket stay open?

However, the connection between a client and your WebSocket app closes when no traffic is sent between them for 60 seconds.


1 Answers

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>
like image 176
Alan Avatar answered Oct 15 '22 04:10

Alan