socket.io保持断开连接,即使我尝试重新连接之后? 为什么?
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;
我不想写所有的代码,因为它有很多,我尽量保持这个简单。 基本上,单击断开连接后,套接字保持断开状态。 但是,如果我再次单击连接,套接字仍然保持断开连接,因为我console.log它说,套接字disconnect = true和套接字connected = false。
为什么它保持断开连接? 我怎么刷新整个套接字(只是得到一个全新的套接字),而不刷新浏览器页面? 我只是希望它在断开连接时完全断开连接,并在重新连接时完全重新连接。 它不工作….
跑到这个相同的问题。 有一个秘密选项force new connection
:
io.connect(url, { 'force new connection' : true })
你也可以使用forceNew
for 1.0。
更多信息: