8000 add connectedClients see #242 · BirdAPI/arduinoWebSockets@4b33575 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4b33575

Browse files
committed
add connectedClients see Links2004#242
1 parent 486a612 commit 4b33575

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/WebSocketsServer.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,24 @@ void WebSocketsServer::setAuthorization(const char * auth) {
403403
}
404404
}
405405

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+
406424
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32)
407425
/**
408426
* get an IP for a client

src/WebSocketsServer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ class WebSocketsServer: protected WebSockets {
9595
void setAuthorization(const char * user, const char * password);
9696
void setAuthorization(const char * auth);
9797

98+
int connectedClients(bool ping = false);
99+
98100
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32)
99101
IPAddress remoteIP(uint8_t num);
100102
#endif

0 commit comments

Comments
 (0)
0