amphp / websocket-client

Async WebSocket client for PHP based on Amp.
https://amphp.org/websocket-client
MIT License
144 stars 17 forks source link

about keep the conection alive #12

Closed pursonc closed 5 years ago

pursonc commented 5 years ago

i suscribed the channel by sending some msg to ws server .if i want to send another msg like ‘ping’ every 30s, where should i add the code in the while loop?

kelunik commented 5 years ago

You can use Loop::repeat to schedule a regularly executed callback, e.g.

Loop::repeat(30 * 1000, function () use ($connection) {
    yield $connection->send(...);
});
bwoebi commented 5 years ago

Umm @kelunik there are some fragments of a keep-alive mechanism? I see artifacts of it (e.g. the OP_PONG handling code), but code emitting the OP_PINGs is missing?

pursonc commented 5 years ago

thx keunik.if the code position below the Loop::run snippet?I have another question that how can i catch some error then reconnection

trowski commented 5 years ago

Closing this issue due to being idle for some time. v1.0.0-rc1 automatically sends ping frames after a user-definable time period if no other messages are sent, so I would recommend upgrading to that. If you have additional questions feel free to reopen this issue or open a new issue.