Socket.io - Manual reconnect after client-side disconnect

javascript, node.js, socket.io, websocket

Solution

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

Problem

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.

Original source