套接字是否在重新连接事件中重用?

Are sockets reused on reconnect event?

当用户连接到服务器时创建套接字。

由于 interwebz 故障,连接中断。

客户端自动重新连接。

socket连接会不会和他第一次连接的时候一样?还是插座是新的?

谢谢!

重新连接时建立新连接。可以通过打印 socket.id.

来检查

在服务器上:

var io = require('socket.io)(server);
io.on('connection', function (socket) {
  console.log('socket id is ' + socket.id); }

Excerpt from socket.io documentation

The property is present once the socket has connected, is removed when the socket disconnects and is updated if the socket reconnects.

我还想在电子应用程序中重新连接后保留状态(例如,如果主机暂停然后恢复,socket.io 会断开连接)。

我还没有尝试过,但下面的文章讨论了如何在重新连接时重用套接字 ID。如果我有任何成功,我会更新: https://newbedev.com/reuse-socket-id-on-reconnect-socket-io-node-js