Socket.io - Manual reconnect after client-side disconnect
If you're using Socket.io 1.0, try using the io
manager on the socket to handle manual disconnection and reconnection.
// Connect to socket.io
var socket = io.connect('url');
function manual_disconnect() {
socket.io.disconnect();
}
function manual_reconnect() {
socket.io.reconnect();
}
The reconnecting_attempt, reconnecting, reconnected and connected events on the socket should all be emitted afterwards.
It works now, with socket.socket.reconnect()
function socket_connect()
{
console.log('func socket_connect');
socket = io.connect('http://url/to/the/app');
}
function socket_reconnect()
{
console.log('func socket_reconnect');
socket.socket.reconnect();
}
function socket_disconnect ()
{
console.log('func socket_disconnect');
if (socket) socket.disconnect();
}
Related: https://github.com/LearnBoost/socket.io-client/issues/251
You can reconnect by following client side config.
// for socket.io version 1.0
io.connect(SERVER_IP,{'forceNew':true });