I working on an websocket server aand in the main handler, I'm facing an issue:
to compare new client to already connected, I must compare them, but doing so, they al came back true... Here the code:
void WebSocketsServer::loop(void) {
//check if client, if it is a new client
EthernetClient client;
client = _server->available();
if (client) {
Serial.println("got client");
for(uint8_t i = 0; i < WEBSOCKETS_SERVER_CLIENT_MAX; i++) {
if( _clients[i].tcp == client ) { //not a new client, handle data ////<<----------- here it bug
Serial.println("client exist");
_clients[i].num = i;
handleClientData(_clients[i]);
return;
}
}
//if you got to that point, it is a new client
for(uint8_t i = 0; i < WEBSOCKETS_SERVER_CLIENT_MAX; i++) {
Serial.println("check free socket");
if (!_clients[i].tcp) { //if emty slot, assing new client then handle it.
Serial.println("free socket");
_clients[i].tcp = client;
Serial.println("handle client");
handleNewClients(_clients[i]);
return;
}
}
client.stop(); //close connection is no free spot
WS_PRINTLN("[WS-Server] No free socket, connection close");
}
//WS_PRINTLN("[WS-Server] No Client");
}
tcp is an ethernetClient object. As in the ethernet class, operator == should compare the two address of client and should return false if the are not the same... or did I miss something...
you asked about EthernetClient, not about websocket. I do not know the websocket specification.
The EthernetClient created by the EthernetServer has always the same 'sock' number as the server has. It can be only one for that server at time.
I have a Telnet server at port 2323 in my project. Until the connection is open for a telnet client, no other telnet client can connect to the server on port 2323.
the problem was about comparing 2 client to see if the were already connected.
I working on an websocket server aand in the main handler, I'm facing an issue:
I do not know all the specification no...
but still, The websocker server have an instance of ethernetServer, then store client in an array, it look to work still...
But I really that I could compare 2 client... I think i will comeback will a pointer to client as the previous version, then I could compare the 2 pointer, and that work...
Thank ( if you have any resource I can look about, feel free.. )