socket.io-client-dart icon indicating copy to clipboard operation
socket.io-client-dart copied to clipboard

Always Reconnect

Open dogusdicle opened this issue 4 years ago • 5 comments

Flutter:

socket = IO.io('http://x.x.x:4047',OptionBuilder().setTransports(['websocket']).disableAutoConnect().build());
socket!.on("connect", (data) => print("connect"));
socket!.on("disconnect", (data) => print("disconnect"));
socket!.on("connect_error", (data) => print("connect_error: $data"));
socket!.on("connect_timeout", (data) => print("connect_timeout: $data"));
socket!.on("connecting", (data) => print("connecting: $data"));
socket!.on("error", (data) => print("error: $data"));
socket!.on("reconnect", (data) => print("reconnect: $data"));
socket!.on("reconnect_attempt", (data) => print("reconnect_attempt: $data"));
socket!.on("reconnect_failed", (data) => print("reconnect_failed: $data"));
socket!.on("reconnect_error", (data) => print("reconnect_error: $data"));
socket!.on("reconnecting", (data) => print("reconnecting: $data"));
socket!.on("ping", (data) => print("ping: $data"));
socket!.on("pong", (data) => print("pong: $data"));
socket!.connect();

Typescript:

const io = require("socket.io")();

io.attach(httpServer, { pingInterval: 10000, pingTimeout: 5000, transports : ["websocket"], serveClient : false });

io.on("connection", function(socket: any) { console.log(socket.id+" connected"); socket.on("message", (message: any) => { }); socket.on("disconnect", (reason: any) => { console.log(socket.id+" disconnect"); }); });

httpServer.listen(4047, () => { console.log('server running '); });

Log:

I/flutter (11614): connect I/flutter (11614): disconnect I/flutter (11614): reconnect_attempt: 1 I/flutter (11614): reconnecting: 1 I/flutter (11614): reconnect: 1 I/flutter (11614): connect I/flutter (11614): disconnect I/flutter (11614): reconnect_attempt: 1 I/flutter (11614): reconnecting: 1 I/flutter (11614): reconnect: 1 I/flutter (11614): connect

There is no problem connecting from another platform (For example angular cli is working), there is this problem with the flutter connection.

dogusdicle avatar Mar 30 '21 21:03 dogusdicle

I had same issue, the server error was:

time="2021-04-01T01:18:54+09:00" level=warning msg="closed:client namespace disconnect"
time="2021-04-01T01:18:54+09:00" level=warning msg="meet error:read tcp 192.168.0.2:8080->192.168.0.2:60551: i/o timeout"

Hanggi avatar Mar 31 '21 16:03 Hanggi

It takes about 30 seconds to reconnect, and when it does, the message is lost.

seekcx avatar Apr 02 '21 16:04 seekcx

I don't know if my solution is useful.

My server is laravel-echo-server. The socket.io version currently supported is 2.3.0, but the socket_io_client version I use is 2.0.0-beta.3-nullsafety.0, and the server version corresponding to this version should be 3.x.

So I fixed socket_io_client to ^1.0.0-nullsafety.0 to solve this problem.

Ping pong works very well.

seekcx avatar Apr 02 '21 17:04 seekcx

Anybody solve this issue? disconnect function is triggering per 30 seconds and reconnect again. I' m using 2.0.0-beta.3-nullsafety.0 version for flutter client.

EDIT : Issue solved. I am using a node.js server and the problem was on the server side. Socket.io version was "2.4.0". I updated to latest version. (4.0.1). Everything works fine now. Hope, it helps someone.

blokberg avatar Apr 13 '21 15:04 blokberg

I don't know if my solution is useful.

My server is laravel-echo-server. The socket.io version currently supported is 2.3.0, but the socket_io_client version I use is 2.0.0-beta.3-nullsafety.0, and the server version corresponding to this version should be 3.x.

So I fixed socket_io_client to ^1.0.0-nullsafety.0 to solve this problem.

Ping pong works very well.

it work :)) thank you

holland-hng avatar Apr 17 '21 15:04 holland-hng