Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket.io - Manual reconnect after client-side disconnect

I use node.js and socket.io to create a real time web application. I will give the users full control of the socket connection, like manual disconnect and (re)connect.

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_connect();
}

function socket_disconnect ()
{
    console.log('func socket_disconnect');
    if (socket) socket.disconnect();
}

On client start up the socket_connect() function works fine, but after using socket.disconnect(), no new connection starts.

like image 649
acc Avatar asked Oct 23 '12 04:10

acc


1 Answers

You can reconnect by following client side config.

 // for socket.io version 1.0
io.connect(SERVER_IP,{'forceNew':true });
like image 139
Prasad Bhosale Avatar answered Oct 14 '22 19:10

Prasad Bhosale