kerryjiang / WebSocket4Net

A popular .NET WebSocket Client
Apache License 2.0
764 stars 273 forks source link

System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host #163

Open prajilal opened 4 years ago

prajilal commented 4 years ago

Hello,

I am using a WebSocket client and experiencing Error event with the following message after sending data continuous for 5 minutes:

System.IO.IOException: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host at System.Net.Sockets.Socket.EndSend(IAsyncResult asyncResult) at System.Net.Sockets.NetworkStream.EndWrite(IAsyncResult asyncResult) --- End of inner exception stack trace --- at System.Net.Security._SslStream.EndWrite(IAsyncResult asyncResult) at System.Net.Security.SslStream.EndWrite(IAsyncResult asyncResult) at SuperSocket.ClientEngine.AuthenticatedStreamTcpSession.OnWriteComplete(IAsyncResult result)

Do you know what may be triggering it?

Note: I have connected to the same server using a JavaScript socket client application and no such issues experienced even after 2 hours.

kerryjiang commented 4 years ago

It looks like a certificate handshake failure?

prajilal commented 4 years ago

Seems not, as it works for some time.

jlnunez89 commented 4 years ago

I'm sort of experiencing the same thing. Mine can run for hours before it hits it. I haven't been able to pinpoint why it seemingly randomly disconnects. I do not own the server though, so it's hard to tell why they're severing the connection on their end. Could it maybe pertain to auto ping?

I'm using: EnableAutoSendPing = true, AutoSendPingInterval = 60, // in seconds.

Breno94re commented 4 years ago

Kinda late to the party, but i know where the problem lies.

for some reason, the Websocket buffer isn't dynamic. Its just reaches it limits after a while... i dont have any ideas why. I noticed that if i'm sending bigger files like images from the client to the server, it wont even work without getting the server buffer to higher numbers. And even at higher numbers, it will "explode" at certain point.

To fix that, the "receive buffer" cant be a declared outside the "listening" block, it has to be set at every new message to the server, otherwise you will be disconnected due to buffer going off-limits..