ESPAsyncWebServer icon indicating copy to clipboard operation
ESPAsyncWebServer copied to clipboard

how to use the keepAlivePeriod for clients ?

Open guestisp opened this issue 3 years ago • 6 comments

I'm trying to find a way to automatically ping all connected clients by using the native ping/pong feature (as workaround i could send custom messages from the client to the server)

I've set this in wsOnEvent:

  if (type == WS_EVT_CONNECT)
  {
    // client connected
    client->printf("Hello Client %u :)", client->id());
    client->ping();
    client->keepAlivePeriod(10);
  }
  else if (type == WS_EVT_PONG)
  {
    // pong message was received (in response to a ping request maybe)
    Serial.printf("ws[%s][%u] pong[%u]: %s\n", server->url(), client->id(), len, (len) ? (char *)data : "");
  }

and i'm expecting a ping/pong every 10 seconds, but nothing happens.

How should I enable the ping/pong ?

guestisp avatar May 13 '22 14:05 guestisp

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 31 '22 03:07 stale[bot]

I have same issue. Trying to find a way to close web socket client when client IP address is not responding to pings (client disconnected). keepAlivePeriod seems to be perfect solution, but it doesn't work. Any other way to close web socket for client that doesn't respond to pings?

simonttp78 avatar Sep 29 '22 17:09 simonttp78

[STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it openin the future.

stale[bot] avatar Sep 29 '22 17:09 stale[bot]

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 18 '23 14:06 stale[bot]