WebSocket4Net icon indicating copy to clipboard operation
WebSocket4Net copied to clipboard

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

Open prajilal opened this issue 6 years ago • 4 comments

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.

prajilal avatar Oct 25 '19 05:10 prajilal

It looks like a certificate handshake failure?

kerryjiang avatar Oct 28 '19 16:10 kerryjiang

Seems not, as it works for some time.

prajilal avatar Oct 29 '19 07:10 prajilal

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.

jlnunez89 avatar Nov 17 '19 08:11 jlnunez89

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..

Breno94re avatar Jan 31 '20 02:01 Breno94re