any workaround on multiple socket.io connection after reconnect

Showing 1-12 of 12 messages
any workaround on multiple socket.io connection after reconnect ved 11/21/11 5:00 AM
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
Re: any workaround on multiple socket.io connection after reconnect ankur 11/21/11 9:52 PM
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

Re: any workaround on multiple socket.io connection after reconnect ankur 11/21/11 10:12 PM
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

Re: any workaround on multiple socket.io connection after reconnect ved 11/21/11 11:39 PM
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
Re: any workaround on multiple socket.io connection after reconnect ankur 11/23/11 3:23 AM
which version of socket.io do you use .. ?

On Nov 22, 12:39 pm, Vedratna Velani <vedpatel2...@gmail.com> wrote:
> 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
>
>
>
>
>
>
>

Re: any workaround on multiple socket.io connection after reconnect ved 11/25/11 12:32 AM
0.8.7 the latest one.

Thanks,
Ved
Re: any workaround on multiple socket.io connection after reconnect ankur 11/29/11 8:44 PM
Is your server under heavy load....!!

On Nov 25, 1:32 pm, Vedratna Velani <vedpatel2...@gmail.com> wrote:
> 0.8.7 the latest one.
>
> Thanks,
> Ved
>
>
>
>
>
>
>

Re: any workaround on multiple socket.io connection after reconnect ved 11/29/11 11:27 PM
yes. sometime.

Thanks,
Ved
Re: any workaround on multiple socket.io connection after reconnect ankur 12/9/11 4:19 AM
i think the issue is solved in jsonp transport . try that and
see......!!

On Nov 30, 12:27 pm, Vedratna Velani <vedpatel2...@gmail.com> wrote:
> yes. sometime.
>
> Thanks,
> Ved
>
>
>
>
>
>
>

Re: any workaround on multiple socket.io connection after reconnect ved 12/9/11 4:49 AM
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
Re: any workaround on multiple socket.io connection after reconnect ved 12/9/11 4:51 AM
To disable reconnection on socket.io-client, I made a small fix here:
https://github.com/LearnBoost/socket.io-client/pull/346

Thanks,
Ved
Re: any workaround on multiple socket.io connection after reconnect Sergii Boiko 12/12/11 5:13 AM
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.