NVentimiglia / Websockets.PCL

C# Websockets for all platforms using native bridges
MIT License
98 stars 36 forks source link

Connection still marked as open after server shutdown #32

Open cesme opened 7 years ago

cesme commented 7 years ago

Hello,

I am using the nuget package 1.1.9 assembly versions droid 1.0.1.8 and PCL 1.0.0.8 and i am noticing that if i shutdown my server the clients will still report that IsOpen is true. Looking through the code in master i wasn't able to locate any timeouts in the Send functions that would mark the connection as closed or trigger an OnError am i missing something in the code ? Is there a proper way to set a send timeout to get the OnError to trigger to detect the server going away ?

thank you

kolbma commented 7 years ago
  1. That's a bug in your server. Your server needs to close the connections before it's going away. This should be handled in OnClose...
  2. If your client should handle server crashes WebSocket provides Ping and Pong.

Your client needs to send Pings to the server and the server must (by standard) respond with a Pong. If there is no Pong coming, the server is not available any longer and the client can throw away connection.

I think Websockets.PCL doesn't support this at the moment. But I think you'll get an OnError on trying to send something. There should be a default time of the sockets. Shouldn't it? Try to wait some more time for this timeout. Can you provide this feedback?

canton7 commented 7 years ago

I'm seeing the OnClosed event being fired, but IsOpen still returns true (on Android).

LeonanFragaLeonardo commented 6 years ago

Hello, Almost a year later and the problem still happens. I have the same problem when I try to close my client-side connection. I call OnClose, the server side closes the connection, but the IsOpen flag is still true. Did someone solve this problem?

--Edit-- For a temporary workaround, I created a new variable called IsOpenedSocket in my project. When the OnClosed or OnError method is called, this flag is set to false and when the OnOpened method is called, this flag is set to true. Did work for me.

MagnusEklof commented 4 years ago

And yet another year... I guess I too will need to keep track of this myself.. even 2 years ;)