reconnect not working in v1.0 #1683

Closed
KaviSharma opened this Issue Jul 16, 2014 · 5 comments

Projects

None yet

4 participants

@KaviSharma

I have this code to connect and disconnect connection-

var socket = io.connect("/dashbaord", {'forceNew': true});
socket.on('connect', function (socket) {
    $log.info("new connection established");
});

socket.on('disconnect', function (socket) {
    $log.info("connection disconnected");
});

//socket connection works here

socket.disconnect(); // disconnect event fire here
socket.connect(); // connect event not fire here

//socket connection does not work here

@matthaywardwebdesign

I think you may need to call io.connect again instead of socket.connect as the forceNew option is destroying the socket and as a result cannot be reused.

@atrigub
atrigub commented Jul 18, 2014

@matthaywardwebdesign But the old connect remains in memory applications

@KaviSharma

OK so I tried these:

  1. with {forceNew: false} option: connect - disconnect - connect -> same result, socket does not work.
  2. after disconnect, executed this code
    socket = io.connect("/dashbaord", {'forceNew': false});
    $log(socket.connected); //false here
    //same result
    //socket does not work here.

socket = io.connect("/dashbaord", {'forceNew': true});
//socket works here, but need to reattach all events.

@KaviSharma

Look at this debug:
screen shot 2014-07-18 at 3 48 46 pm

not sure what forceNew: false does. And can we reuse/reconnect an existing connection ? setting up a new connection every time io.connect is tedious as have to attach all events again. And old connection objects still exists in memory.

@rase-
Contributor
rase- commented Jan 12, 2015

Should work after merging socketio/socket.io-client#732

@rase- rase- closed this Jan 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment