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

Handle ping/pong frames. #5

Closed
ogayot opened this issue Jun 23, 2015 · 1 comment
Closed

Handle ping/pong frames. #5

ogayot opened this issue Jun 23, 2015 · 1 comment

Comments

@ogayot
Copy link
Contributor

ogayot commented Jun 23, 2015

I am having some issues with certain browsers (mainly on embedded devices) that send ping (opcode 0x09) and/or pong (opcode 0x0A) frames without being solicited.

With the current implementation, those frames are handled like any text message (opcode 0x01) and there is no way to differenciate them from actual messages. The only workaround I found is to check if the payload of the frame matches a specific text (e.g. "PING"). IMHO the solution is rather unclean.

I am thinking of two ways to deal with the issue:

  • either make the server automatically send a pong frame whenever it receives a ping frame and not call the callback message_received()
  • add another callback which is called when a ping frame is received and let the user deal with it.

I can probably help with the code if needed.

Thank you by advance for reading :)

@Pithikos
Copy link
Owner

You are right. A major problem is that I don't actually check for the OPCODE of any message received except for a CLOSE_CONN opcode. There should be a warning or something when a non-supported OPCODE arrives (in this case PONG).

As about implementation I think what makes sense (at least to me) is to check if the opcode is PING in read_next_message(). Then a send_pong() method needs to be implemented which just sends the pong response. In that way things are kept quite simple and intuitive.

Feel free to implement it if you want. I am jobless atm so I have no time to do any changes unfortunately.. If the implementation works fine and is consistent with the rest of the code, I can merge it.

shenek pushed a commit to shenek/python-websocket-server that referenced this issue Feb 13, 2017
Whenever we receive a PING frame, we have to reply with a PONG frame
with a payload identical to the one present in the received PING.

we reuse the function send_text() to send the pong frame but add the
opcode to be sent as an argument. This opcode defaults to OPCODE_TEXT so
we do not break the compatibility.

fixes Pithikos#5

Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
shenek pushed a commit to shenek/python-websocket-server that referenced this issue Feb 13, 2017
Whenever we receive a PING frame, we have to reply with a PONG frame
with a payload identical to the one present in the received PING.

we reuse the function send_text() to send the pong frame but add the
opcode to be sent as an argument. This opcode defaults to OPCODE_TEXT so
we do not break the compatibility.

fixes Pithikos#5

Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
shenek pushed a commit to shenek/python-websocket-server that referenced this issue Feb 13, 2017
Whenever we receive a PING frame, we have to reply with a PONG frame
with a payload identical to the one present in the received PING.

we reuse the function send_text() to send the pong frame but add the
opcode to be sent as an argument. This opcode defaults to OPCODE_TEXT so
we do not break the compatibility.

fixes Pithikos#5

Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants