File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -403,6 +403,24 @@ void WebSocketsServer::setAuthorization(const char * auth) {
403
403
}
404
404
}
405
405
406
+ /* *
407
+ * count the connected clients (optional ping them)
408
+ * @param ping bool ping the connected clients
409
+ */
410
+ int WebSocketsServer::connectedClients (bool ping) {
411
+ WSclient_t * client;
412
+ int count = 0 ;
413
+ for (uint8_t i = 0 ; i < WEBSOCKETS_SERVER_CLIENT_MAX; i++) {
414
+ client = &_clients[i];
415
+ if (client->status == WSC_CONNECTED) {
416
+ if (ping != true || sendPing (i)) {
417
+ count++;
418
+ }
419
+ }
420
+ }
421
+ return count;
422
+ }
423
+
406
424
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32)
407
425
/* *
408
426
* get an IP for a client
Original file line number Diff line number Diff line change @@ -95,6 +95,8 @@ class WebSocketsServer: protected WebSockets {
95
95
void setAuthorization (const char * user, const char * password);
96
96
void setAuthorization (const char * auth);
97
97
98
+ int connectedClients (bool ping = false );
99
+
98
100
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32)
99
101
IPAddress remoteIP (uint8_t num);
100
102
#endif
You can’t perform that action at this time.
0 commit comments