question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Socket.io - Client 3.0.0+ reconnect event all failed

See original GitHub issue

Socket.io - Client 3.0.0+ reconnect event all failed.

Switch to version 2.3.1 and it works.

const io = require('socket.io-client');

let socket = io.connect('ws://127.0.0.1:8000', {
    "transports": ['websocket', 'polling'],
    reconnection: true
});
socket.on('connect', function(data){
    onlineFlag = true;
    console.log(data + ' - connect');
});
socket.on('connect_error', function(data){
    console.log(data + ' - connect_error');
});
socket.on('connect_timeout', function(data){
    console.log(data + ' - connect_timeout');
});
socket.on('error', function(data){
    console.log(data + ' - error');
});
socket.on('disconnect', function(data){
    onlineFlag = false;
    console.log(data + ' - disconnect');
});
socket.on('reconnect', function(data){
    console.log(data + ' - reconnect');
});
socket.on('reconnect_attempt', function(data){
    console.log(data + ' - reconnect_attempt');
});
socket.on('reconnecting', function(data){
    console.log(data + ' - reconnecting');
});
socket.on('reconnect_error', function(data){
    console.log(data + ' - reconnect_error');
});
socket.on('reconnect_failed', function(data){
    console.log(data + ' - reconnect_failed');
});
socket.on('ping', function(data){
    console.log(data + ' - ping');
});
socket.on('pong', function(data){
    console.log(data + ' - pong');
});

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
darrachequesnecommented, Jan 2, 2021

@newpanjing hi! What do you mean by “reconnect event all failed” ?

As pointed out by @tannerkrewson (thanks!), the Socket instance no longer emits any reconnection events.

// no longer emitted
socket.on("reconnect_attempt", () => {});
// but you can listen to the events emitted by the Manager instance (the io attribute)
socket.io.on("reconnect_attempt", () => {});
1reaction
tannerkrewsoncommented, Jan 2, 2021

Would it be possible to have a warning message in the console if someone tries to use those events on the socket itself? I think that would be super helpful for people migrating, instead of it silently failing. 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Migrating from 2.x to 3.0 - Socket.IO
Catch-all listeners; Volatile events (client); Official bundle with the ... reconnect_failed, reconnection failure after all attempts, - ...
Read more >
socket.io javascript client fails to reconnect after restarting server
I listen to a "disconnect" event to rebind a new 'connect' event. This way, if you server is restarted, the local client will...
Read more >
socket_io_client | Dart Package - Pub.dev
Dartlang port of socket.io-client for web, flutter, dartvm to use. ... as this will cause all event handlers to get registered/fired twice. See...
Read more >
socket.io-client - npm
The source code of the website can be found here. Contributions are welcome! Debug / logging. In order to see all the client...
Read more >
socket.io-client | Yarn - Package Manager
socket.io-client. owner socketio19.1mMIT4.5.4TS vulns 0 vulnerabilities. Realtime application framework client. realtime, framework, websocket, tcp ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found