socket.io仍然断开连接,即使我尝试重新连接它?为什么?

时间:2015-04-15 19:37:30

标签: javascript node.js sockets socket.io client

socket = 'what';
//I do this when person clicks connect: 
if (socket == 'what')
{
socket = io.connect();
}
else if (socket == null)
{
 socket = io.connect();
 socket = socket.socket.reconnect();
 }
//I do other stuff with webrtc and socket. 
//then when person clicks disconnect, I do:
socket.disconnect();
socket = null;

我不想编写所有代码,因为它有很多代码,我尽量保持这个简单。基本上,单击断开连接后套接字仍然断开连接。但是,如果我再次单击connect,socket仍然保持断开状态,因为我在console.log它并且它表示socket disconnected = true且socket connected = false。

为什么它仍然断开连接?如何在不刷新浏览器页面的情况下完全刷新整个套接字(只需一个全新的套接字)?我只是希望它在断开连接时完全断开,并在重新连接时完全重新连接。它没有用......

1 个答案:

答案 0 :(得分:1)

进入同样的问题。有一个秘密选项force new connection

io.connect(url, { 'force new connection' : true })

您也可以将forceNew用于1.0。

更多信息:

https://github.com/Automattic/socket.io-client/issues/607

相关问题