compare two ethernet client always return true ?

Hi.

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…

Regards

Nitrof

it compares the 'socket' number and it is the same for all clients of the server. only one remote client can be connected to an EthernetServer

only one remote client can be connected to an EthernetServer

To be certain, I loaded a previous version that was working, and I can connect 2 device at the same time…

it compares the ‘socket’ number and it is the same for all clients of the server

from EthernetClient class:

virtual bool operator==(const EthernetClient&);
  virtual bool operator!=(const EthernetClient& rhs) { return !this->operator==(rhs); };

is that not that those overload compare the address of the instance of ethernetClient ???

nitrof:
To be certain, I loaded a previous version that was working, and I can connect 2 device at the same time...

from EthernetClient class:

virtual bool operator==(const EthernetClient&);

virtual bool operator!=(const EthernetClient& rhs) { return !this->operator==(rhs); };



is that not that those overload compare the address of the instance of ethernetClient ???

not at the same time. after you stop the connection the next client is handled.

bool EthernetClient::operator==(const EthernetClient& rhs) {
 return _sock == rhs._sock && _sock != MAX_SOCK_NUM && rhs._sock != MAX_SOCK_NUM;
}

not at the same time. after you stop the connection the next client is handled

It is a web socket server, so is that not the basic of it ?? persistent connection ??

And the operator overload came from Ethernet2.. if that mater... (probably)...

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.. :slight_smile: )

Regards

Nitrof