27
27
28
28
WebSocketsServer::WebSocketsServer (uint16_t port) {
29
29
_port = port;
30
- _server = new WiFiServer (port);
30
+ _server = new WEBSOCKETS_NETWORK_SERVER_CLASS (port);
31
31
32
32
_cbEvent = NULL ;
33
33
@@ -240,6 +240,7 @@ void WebSocketsServer::disconnect(uint8_t num) {
240
240
}
241
241
}
242
242
243
+ #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266)
243
244
/* *
244
245
* get an IP for a client
245
246
* @param num uint8_t client id
@@ -255,6 +256,7 @@ IPAddress WebSocketsServer::remoteIP(uint8_t num) {
255
256
256
257
return IPAddress ();
257
258
}
259
+ #endif
258
260
259
261
// #################################################################################
260
262
// #################################################################################
@@ -363,18 +365,22 @@ bool WebSocketsServer::clientIsConnected(WSclient_t * client) {
363
365
*/
364
366
void WebSocketsServer::handleNewClients (void ) {
365
367
WSclient_t * client;
368
+ #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266)
366
369
while (_server->hasClient ()) {
370
+ #endif
367
371
bool ok = false ;
368
372
// search free list entry for client
369
373
for (uint8_t i = 0 ; i < WEBSOCKETS_SERVER_CLIENT_MAX; i++) {
370
374
client = &_clients[i];
371
375
372
376
// state is not connected or tcp connection is lost
373
377
if (!clientIsConnected (client)) {
374
-
378
+ # if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266)
375
379
// store new connection
376
380
client->tcp = new WEBSOCKETS_NETWORK_CLASS (_server->available ());
377
-
381
+ #else
382
+ client->tcp = new WEBSOCKETS_NETWORK_CLASS (_server->available ());
383
+ #endif
378
384
if (!client->tcp ) {
379
385
DEBUG_WEBSOCKETS (" [WS-Client] creating Network class failed!" );
380
386
return ;
@@ -387,9 +393,12 @@ void WebSocketsServer::handleNewClients(void) {
387
393
// set Timeout for readBytesUntil and readStringUntil
388
394
client->tcp ->setTimeout (WEBSOCKETS_TCP_TIMEOUT);
389
395
client->status = WSC_HEADER;
390
-
396
+ # if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266)
391
397
IPAddress ip = client->tcp ->remoteIP ();
392
398
DEBUG_WEBSOCKETS (" [WS-Server][%d] new client from %d.%d.%d.%d\n " , client->num , ip[0 ], ip[1 ], ip[2 ], ip[3 ]);
399
+ #else
400
+ DEBUG_WEBSOCKETS (" [WS-Server][%d] new client\n " , client->num );
401
+ #endif
393
402
ok = true ;
394
403
break ;
395
404
}
@@ -398,15 +407,21 @@ void WebSocketsServer::handleNewClients(void) {
398
407
if (!ok) {
399
408
// no free space to handle client
400
409
WEBSOCKETS_NETWORK_CLASS tcpClient = _server->available ();
401
- IPAddress ip = tcpClient.remoteIP ();
410
+ #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266)
411
+ IPAddress ip = client->tcp ->remoteIP ();
402
412
DEBUG_WEBSOCKETS (" [WS-Server] no free space new client from %d.%d.%d.%d\n " , ip[0 ], ip[1 ], ip[2 ], ip[3 ]);
413
+ #else
414
+ DEBUG_WEBSOCKETS (" [WS-Server] no free space new client\n " );
415
+ #endif
403
416
tcpClient.stop ();
404
417
}
405
418
406
419
#ifdef ESP8266
407
420
delay (0 );
408
421
#endif
422
+ #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266)
409
423
}
424
+ #endif
410
425
}
411
426
412
427
/* *
0 commit comments