any workaround on multiple socket.io connection after reconnect

6,956 views
Skip to first unread message

Vedratna Velani

unread,
Nov 21, 2011, 8:00:53 AM11/21/11
to sock...@googlegroups.com
Hi guys,

I know this is known issue right now: https://github.com/LearnBoost/socket.io/issues/430

But I want to know if anybody knows any workaround to get rid of multiple connection after this as I want to avoid multiple update with this.

At client side will socket.disconnect() removes all the connections? will following code works to remove multiple connection after reconnect?

socket = io.connect(url)
socket.on('connect', function(){
if(multipleConnect) {
socket.disconnect();
socket.removeAllListeners('connect');
io.sockets = {};
socket = io.connect(url);
socket.on('connect', functionToConnect);
}
})

I am not able to test this locally as not able to reproduce it locally.

Thanks,
Ved

ankur

unread,
Nov 22, 2011, 12:52:16 AM11/22/11
to Socket.IO
I had a similar problem affecting my code
what i did was add the listener methods outside of 'connect' function,
now i get only one event fired

instead of this


socket = io.connect(url)
socket.on('connect', function(){

socket.on('message', function (msg) {
});
});

now i do


socket = io.connect(url)
socket.on('connect', function(){

});

socket.on('message', function (msg) {
});

it appears work right..
hope this helps

ankur

unread,
Nov 22, 2011, 1:12:20 AM11/22/11
to Socket.IO
i had the same problem , was getting multiple events on receiving
data.
instead of this

socket = io.connect(url);
socket.on('connect', function () {

socket.on('message', function (msg) {
});
});

i did this,

socket = io.connect(url);
socket.on('connect', function () {

});
socket.on('message', function (msg) {
});

this seems to work all right and multiple events don't seem to fire.
i think it is because previous registered listener doesn't gets
unregistered after a successful re-connection attempt

Vedratna Velani

unread,
Nov 22, 2011, 2:39:30 AM11/22/11
to sock...@googlegroups.com
I am already having the second implementation and it doesn't seem to work for me, to me it looks like multiple connections gets generated on same 'socket' reference, because I have 'socket = io.connect(url) only once in my code, where socket gets assigned and like your second implementation I am adding evenlisteners to same socket independently, not inside the 'connect'. So it can't be get reassigned automatically on reconnection.

Thanks,
Ved

ankur

unread,
Nov 23, 2011, 6:23:18 AM11/23/11
to Socket.IO
which version of socket.io do you use .. ?

Vedratna Velani

unread,
Nov 25, 2011, 3:32:37 AM11/25/11
to sock...@googlegroups.com
0.8.7 the latest one.

Thanks,
Ved

ankur

unread,
Nov 29, 2011, 11:44:36 PM11/29/11
to Socket.IO
Is your server under heavy load....!!

Vedratna Velani

unread,
Nov 30, 2011, 2:27:59 AM11/30/11
to sock...@googlegroups.com
yes. sometime.

Thanks,
Ved

ankur

unread,
Dec 9, 2011, 7:19:30 AM12/9/11
to Socket.IO
i think the issue is solved in jsonp transport . try that and
see......!!

Vedratna Velani

unread,
Dec 9, 2011, 7:49:55 AM12/9/11
to sock...@googlegroups.com
overall issue is not fixed yet. And I want to use websocket where issue is still there. It is regarding opening multiple transport at the same time. I think it has been fixed by 3rd-Eden in his branch where he fixed the multiple reconnection issue. He already did pull request, so fix might come with next socket.io release. Till that as a workaround I choose to disable reconnection on socket-io-client, I am handling it outside.

Thanks,
Ved

Vedratna Velani

unread,
Dec 9, 2011, 7:51:42 AM12/9/11
to sock...@googlegroups.com
To disable reconnection on socket.io-client, I made a small fix here:
https://github.com/LearnBoost/socket.io-client/pull/346

Thanks,
Ved

Sergii Boiko

unread,
Dec 12, 2011, 8:13:44 AM12/12/11
to sock...@googlegroups.com
I've did a fix, but it works only for JSONP-kind of handshake.

You can disable appropriate condition and prevents AJAX-handshake. So it will work for anybody.
Reply all
Reply to author
Forward
0 new messages