Skip to content
This repository has been archived by the owner on Feb 15, 2023. It is now read-only.

Reconnect fails #17

Open
sinokgr opened this issue Dec 24, 2021 · 6 comments
Open

Reconnect fails #17

sinokgr opened this issue Dec 24, 2021 · 6 comments

Comments

@sinokgr
Copy link

sinokgr commented Dec 24, 2021

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

@NicoAiko
Copy link

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

@sinokgr
Copy link
Author

sinokgr commented Jan 10, 2022

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.

@NicoAiko
Copy link

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

@sinokgr
Copy link
Author

sinokgr commented Jan 10, 2022

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

@NicoAiko
Copy link

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
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants