Lawouach / WebSocket-for-Python

WebSocket client and server library for Python 2 and 3 as well as PyPy (ws4py 0.5.1)
https://ws4py.readthedocs.org/en/latest/
BSD 3-Clause "New" or "Revised" License
1.12k stars 288 forks source link

Heartbeat Pong Message (why not Ping?) #148

Open grubberr opened 10 years ago

grubberr commented 10 years ago

Hello,

I am curious why in Heartbeat context manager you send PongControlMessage ?

https://github.com/Lawouach/WebSocket-for-Python/blob/master/ws4py/websocket.py#L55

for me more logically to send PingControlMessage ?

Thanks in advance!

Lawouach commented 10 years ago

Hi,

2014-09-30 8:08 GMT+02:00 grubberr notifications@github.com:

Hello,

I am curious why in Heartbeat context manager you send PongControlMessage ?

https://github.com/Lawouach/WebSocket-for-Python/blob/master/ws4py/websocket.py#L55

for me more logically to send PingControlMessage ?

Thanks in advance!

I think I always considered the heartbeat to be a receiver of Ping messages but you have a point actually. Mind you, these days the class is still there but not uactually used anyhow. Well, unless you directly create a WebSocket instance yourself and call its run method. This is not used by any of the server/client in ws4py anylonger.

grubberr commented 10 years ago

reading some simple articles about websocket I initially also thought that websocket library has to re-connect using some ping-pong heartbeat

maybe re-implementing this Hearbeat class for receiving pings really good point

anyway in my code I have own heartbeat thread which checks if connection alive using incoming data and I want to re-implement based on incoming ping messages

but I am stuck on such thing:

I cannot find method which will be executed if ping message arive

I only need to patch ws4py

Lawouach commented 9 years ago

I think I ought to implement a "pinged()" handler indeed.

bkcsfi commented 9 years ago

Hi,

We're using ws4py and need finer grained control over ping/pong handling. We really could use a 'pong_received' event handler and a method to manually trigger the sending of a ping message. This, in addition to regular periodic ping requests being automatically generated by ws4py.

that is, we need to know when the remote end has responded to our ping request, to manually initiate a ping request and to have a regular ping request sent.

bonus if we also could have a ping_received event as well.

thanks