Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document 'ping' and 'pong' events in http://socket.io/docs #1022

Closed
joonas-lahtinen opened this issue Nov 13, 2016 · 13 comments
Closed

Document 'ping' and 'pong' events in http://socket.io/docs #1022

joonas-lahtinen opened this issue Nov 13, 2016 · 13 comments

Comments

@joonas-lahtinen
Copy link

ping and pong events are undocumented in the website (socket.io/docs), potentially causing confusion when somebody tries to implement their own ping-pong system. socket.emit('pong') on the browser does not cause anything to be sent over the socket (verified with localStorage.debug = '*';), maybe socket.emit('ping') should also report an error letting the developer know it's a reserved keyword.

From README.md:

- `ping`. Fired when a ping packet is written out to the server.
- `pong`. Fired when a pong is received from the server.
    Parameters:
    - `Number` number of ms elapsed since `ping` packet (i.e.: latency)."
@hugohil
Copy link

hugohil commented Nov 24, 2016

Agreed!
I know one must read the fabulous manual, but I still managed to lost a couple of hours (and hair) figuring out why the hell my code wasn't working.
Totally my fault, but I would have liked it a lot if I was thrown some warning saying "Those events are reserved, try something else".

@darrachequesne
Copy link
Member

PR is welcome, as usual!

@joonas-lahtinen
Copy link
Author

I already considered that, but I failed to find a repository that contains the website source. Maybe I'm just incompetent or was too tired, can you point me to it?

@hugohil
Copy link

hugohil commented Nov 24, 2016

I just started looking at this (see here) but this comes with a need of something like a verbose parameter. Plus I'm pretty sure this is also triggered by those "internal" events. And finally console.warn.calledWith() does not exist in expect.
Still need some work ...

@darrachequesne
Copy link
Member

Closing due to inactivity, please reopen if needed.

@joonas-lahtinen
Copy link
Author

It's hard to know if the issue was fixed or not, due to #1054 (the page renders nothing currently).

@ForgeableSum
Copy link

Is ping/pong not some real basic shit in networking? why the hell would they not be documented? There are ping and pong events sent back and fourth between the server and client automatically (upon socket connection)? If so, how do i look at these events and their timestamps to measure latency?

@tcaer
Copy link

tcaer commented Jun 20, 2017

Can we reopen this, I agree with ForgeableSum. We should have more documentation.

@devniel
Copy link

devniel commented Jan 12, 2018

Well it's already documented https://github.com/socketio/socket.io-client/blob/master/docs/API.md#event-ping-1 , I was struggling for hours trying to receive data from a custom ping event sent by my client, it seems that you can't override this event. 😅

@dbartokthomas
Copy link

Ugh. I just burnt loads of time here. RTFM.

@dmlo
Copy link

dmlo commented Jun 21, 2021

As this page is now the top result when searching for 'socket.io ping pong events':

If you are making your own 'ping' and 'pong' events and they are behaving strangely, it is because socket.io is using those events internally to monitor the connection. Rename your own events to something else like 'my-ping' and 'my-pong' and they will work as expected.

@darrachequesne
Copy link
Member

@dmlo please note that this is not true anymore in version > 3.0.0, you can totally use ping and pong in your application.

Reference:

Using a reserved event will now throw an error, as suggested in a comment above:

// will throw an error
socket.emit("connect");

@dmlo
Copy link

dmlo commented Jun 21, 2021

@darrachequesne Thank you for the clarification. I am indeed using 2.4 with NestJS. They suggest support for 3.0 is coming in the next major version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants