-
Notifications
You must be signed in to change notification settings - Fork 371
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
How to send PING? #86
Comments
instead of using dummy data use : $this->send($user,$message,'ping'); The client will respond with a pong. Or if you don't need or want an answer from client you can send directly a 'pong'. |
@Xaraknid it's not about the message but the "pong frame" Having the same issue here, after a while i am getting a disconnect (executed from browser) because the server appears inactive to the JS websocket. So far i have found no solutions online how to do that though. |
Ok it's been a while I worked on that and by that time I fork it and change alot of thing including the command send. If you want the server to send a ping you can do that. You'll can do it by adding a new function inside websocket.php
and modified it to that
After that from from your server loop up to you to use your own method to call that function at certain interval to keep connection alive. |
I will give that a try, but it is weird that the server has to send the ping instead of the client I saw a ping request happen from client->server once, and had some checks to validate if the server responds with pong - it did send it, but the client disconnected regardless. |
Maybe the connection close because of network issue. You are right it's not required that the server send the ping or the client the purpose of ping-pong other than to know the latency can be use to keep the connection alive at application level by sending data on it if there is a long time between transmission. As I said above you can also directly send a pong instead of a ping and the client will receive it and not respond to that reducing data flow. After that you need to know if it's server or client side that close the connection. If it's server side you can add the option keep alive on the TCP that will make another layer of keeping connection alive as it'll do on TCP level ( 2 hours time frame check ). You can do that by adding SO_KEEPALIVE on the line 22 of websocket.php
|
I have SO_KEEPALIVE set and i know that the client closes the connection since i got this bit of code:
So the message logged was
|
Indeed it happens at TCP level and each browser have their own default settings for TIMEOUT preventing keeping ghost connection. So the only solution is to keep sending stuff. You can do it on client side with a ping and server respong pong or the server sending ping or pong directly with pong the client didn't have to respond to it. |
A proxy between the client and my server disconnects the websocket connection if no data crosses the wire in any 100 second span.
To fix this I'm currently sending dummy data on a timed schedule, but that's a very clumsy solution.
I notice that if the browser sends a
PING
, thePHP-Websockets
server will correctly reply with aPONG
. How can I send aPING
from the server? I'm willing to modify the server's PHP file to do so.The text was updated successfully, but these errors were encountered: