SocketIOSharp icon indicating copy to clipboard operation
SocketIOSharp copied to clipboard

Reconnect fails

Open sinokgr opened this issue 4 years ago • 6 comments

Hi All,

I'm trying SocketIOSharp on mini project I'm working on, and I'm having one issue. Every time I restart the server, I'm getting an error.

Node.JS server below.

const express = require('express');
const app = express();
const http = require('http').Server(app);
const io = require('socket.io')(http);
const port = process.env.PORT || 80;

io.on('connection', (socket) => {
    console.log(socket);
});

http.listen(port, () => {
  console.log('listening on port:' + port);
});

Error

24/12/2021 18:28:19|Fatal|<>c__DisplayClass52_0.<ReadBytesAsync>b__0|System.IO.IOException: Unable to read data from 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.EndReceive(IAsyncResult asyncResult)
                             at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
                             --- End of inner exception stack trace ---
                             at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
                             at WebSocketSharp.Ext.<>c__DisplayClass52_0.<ReadBytesAsync>b__0(IAsyncResult ar) in D:\repositories\uhm0311\websocket-sharp\websocket-sharp\Ext.cs:line 674 :
EngineIOSharp.Client.Transport.EngineIOPolling : EngineIOSharp.Common.EngineIOException: Error ---> System.Net.WebException: The remote server returned an error: (400) Bad Request.
   at EngineIOSharp.Client.Transport.EngineIOPolling.Request(EngineIOHttpMethod Method, Object EncodedPacket, Action`1 ErrorCallback) in D:\repositories\uhm0311\EngineIOSharp\EngineIOSharp\Client\Transport\EngineIOPolling.cs:line 156
   --- End of inner exception stack trace ---

Any ideas why this happening? Reconnect default settings seem fine, so I'm a bit confused. I searched online but I didn't find anything similar.

Many thanks, Nick

sinokgr avatar Dec 24 '21 16:12 sinokgr

Yeah, I get this problem too. I stopped the server (express/NestJS) and restarted it. After the server got back online, the C# program kept logging that it couldn't connect, with the same error message you have.

So far I have not been able to fix this problem. Is it a problem on the server-side or client-side? Because after restarting the client-side, the connection works fine. :/

NicoAiko avatar Jan 10 '22 16:01 NicoAiko

I'm pretty sure it's client side @NicoAiko. I've used my NodeJS server many times in the past along with the JS Library from Socket.IO and I never had this issue.

sinokgr avatar Jan 10 '22 16:01 sinokgr

@sinokgr Which version of socket.io do you use?

NicoAiko avatar Jan 10 '22 16:01 NicoAiko

@NicoAiko , you mean for the server? and old version, it wasn't working with the new versions at all for me. I'm not at the PC with that code at the moment to check specifically.

sinokgr avatar Jan 10 '22 16:01 sinokgr

Because I use NestJS v7 which uses Socket.IO v2. https://socket.io/docs/v4/client-installation/#version-compatibility

There is the possibility that SocketIOSharp, which uses v4 (at least if I interpret it correctly) is not fully compatible and the reconnect functionality is not working for that reason. image

I have yet to check if Socket.IO v4 (server-side) works or not though.

NicoAiko avatar Jan 10 '22 16:01 NicoAiko

I checked with v4 of the socket.io server nodejs package and yeah... it didn't work.

It'll probably be necessary to change the client package to another one.

NicoAiko avatar Jan 11 '22 12:01 NicoAiko