好吧,您可以在这里选择…
首次初始化套接字值时,应使用
io.connect,
下次(调用一次断开连接后),您应使用再次连接
socket.socket.connect()。
所以你的
initSocket应该是这样的
function initSocket(__bool){ if(__bool){ if ( !socket ) { socket = io.connect('http://xxx.xxx.xxx.xxx:8081', {secure:false}); socket.on('connect', function(){console.log('connected')}); socket.on('disconnect', function (){console.log('disconnected')}); } else { socket.socket.connect(); // Yep, socket.socket ( 2 times ) } }else{ socket.disconnect(); // socket = null; <<< We don't need this anymore }}


