melihbudak / jquery-websocket

Automatically exported from code.google.com/p/jquery-websocket
0 stars 0 forks source link

Starting two websockets on the same page causes mixup of sockets - fix attached. #8

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create a web page that opens two WebSockets to a defined Server. 
2. Implement a simple ping-pong message protocol, where both sockets expect a 
pong message on their own socket after they have sent a message.
3. Let both websockets send a ping message.

The expected output is that each socket receives a pong.  Instead both pongs 
message events are handled by one client socket message handler, the one that 
was created last.

This was tested with latest Chrome and Firefox browsers using the HTML5 
WebSocket class. I am using version 0.0.1 of jquery-websocket.

Analyzing the issue we found that the jquery-websocket-0.0.1 script is faulty 
as described below:

After initialisation of the local variable 'ws', 'ws._settings' is set to the 
merge result of the jquery static 'websocketSettings' and input parameter 's'. 
but the extend function modifies the first argument and so the static variable 
gets poisoned each time a new websocket is created. This lead to other strange 
symptoms as well, when we tried to reinstanciate the broken socket. 

We wrote a fix for this issue, please update.

Original issue reported on code.google.com by kai.hack...@gmail.com on 14 Aug 2012 at 2:20

Attachments:

GoogleCodeExporter commented 8 years ago
FYI - per http://code.google.com/p/jquery-websocket/issues/detail?id=9, I 
forked this lib and fixed this issue (a bit differently from your fix). Please 
feel free to submit issues/pull requests over there.

Cheers,
David

Original comment by dchelim...@gmail.com on 20 Sep 2012 at 8:54