How to drop old messages on browser window reload? (Messages are duplicated)

54 views
Skip to first unread message

Frederic Hemberger

unread,
Mar 2, 2012, 5:57:00 AM3/2/12
to sock...@googlegroups.com

Just started my first Socket.IO project and everything is working fine so far. However, I have a question about my current setup:

I have a server job which takes some time to run, so I'm using Socket.IO to push updates about the process to the client. When the process is finished, I close the connection. But as soon as the client refreshes the result page or closes and reopens the URL in the browser, he receives again every message which has been sent so far.

This leads to the following behavior:

First run:
debug: websocket writing 5:::{"name":"debug","args":["Loading data ..."]}
debug: websocket writing 5:::{"name":"debug","args":["Data received: 10859 bytes"]}
debug: websocket writing 5:::{"name":"debug","args":["Processing result ..."]}

Second run (Browser window reload):
debug: websocket writing 5:::{"name":"debug","args":["Loading data ..."]}
debug: websocket writing 5:::{"name":"debug","args":["Loading data ..."]}
debug: websocket writing 5:::{"name":"debug","args":["Data received: 10859 bytes"]}
debug: websocket writing 5:::{"name":"debug","args":["Processing result ..."]}
debug: websocket writing 5:::{"name":"debug","args":["Data received: 10859 bytes"]}
debug: websocket writing 5:::{"name":"debug","args":["Processing result ..."]}

Is there any way to drop the old messages, which have already been received by the client and only send the new ones (since the connection has been started again)? I already tried socket.volatile.emit instead of socket.emit without luck.

Pavel Sakun

unread,
Mar 2, 2012, 7:40:06 AM3/2/12
to sock...@googlegroups.com
Hi Frederic.

Check your code for duplicate handlers. Most likely there is single message, but 2 handlers for the same event/message.

Pavel.
--
Best regards.
Pavel.

Frederic Hemberger

unread,
Mar 2, 2012, 8:37:30 AM3/2/12
to sock...@googlegroups.com
Hi Pavel,

no, there is only one handler on the server and on the client.

For the server request to "/result", I
1) open a new socket connection
2) start emitting the event messages to the client asynchronously
3) close the socket connection, once the last callback function is fired.

Guillermo Rauch

unread,
Mar 2, 2012, 10:29:13 AM3/2/12
to sock...@googlegroups.com
What browser is this ?
--
Guillermo Rauch
LearnBoost CTO
http://devthought.com

Frederic Hemberger

unread,
Mar 2, 2012, 11:29:40 AM3/2/12
to sock...@googlegroups.com

Am Freitag, 2. März 2012 16:29:13 UTC+1 schrieb Guillermo Rauch:
What browser is this ?
Chrome 19.0.1055.1/Mac (Dev-Channel) using Web-Sockets. Re-checked with today's 0.9.1-1 release.

If you think it might be a bug (instead of just a misconfiguration/misuse from my side), I can try to build a isolated test case and file it as an issue.

Pavel Sakun

unread,
Mar 5, 2012, 4:03:06 PM3/5/12
to sock...@googlegroups.com
It would be ideal bug report :)
--
Best regards.
Pavel.
Reply all
Reply to author
Forward
0 new messages