-->
Page 1 of 2

TCP simultaneous clients conflicts!!

PostPosted: Thu Aug 02, 2018 7:18 am
by MrOmar
I'm trying to send a line of data from specific number of clients to one server according to those conditions:
- all the clients are trying to connect to server at same time
- server should stop all connections almost together, when the last client already sent it's data (in order to keep clients working simultaneously in their other tasks).

Server's code (receiving block) :
Code: Select allint j=0;
while(j<CLIENTS_NUM)
{
   
     WiFiClient cl = server.available();
     if(cl)
     {
        if(!Client_Registered(cl)) // check if the client is not already registered in "Clients[ ]" (by remote ip)
        {
            Clients[j] = cl;
            if(Clients[j].available())
            {
              char Station_ID = Clients[j].read();
              String Str = Clients[j].readStringUntil('C'); // char 'C' is the last in data line.
              while(Clients[j].available()) { char c = Clients[j].read(); }
              ++j;
            }
        }
     }
}
j=0;
while(j<CLIENTS_NUM)
{
     Clients[j].stop();
     ++j;
}


Client's code (transmitting block):
Code: Select all  while(!client.connect(server,8008))  delay(100);
  client.write(INTEGER);
  client.println(FLOAT);
  client.write('C');
  while(client.connected()) delay(1);
  WiFi.disconnect();


The problem is that the server is stop responding or stuck in somewhere after receiving data from the first client.

Re: TCP simultaneous clients conflicts!!

PostPosted: Thu Aug 02, 2018 10:19 am
by RichardS
Could you post the code for the Client_Registered() ??

RichardS

Re: TCP simultaneous clients conflicts!!

PostPosted: Fri Aug 03, 2018 10:46 am
by RichardS
I think also client.write() only sends out a byte so the write(INTEGER) seems odd....

Can you post the other code?

RichardS

Re: TCP simultaneous clients conflicts!!

PostPosted: Fri Aug 03, 2018 2:09 pm
by MrOmar
Thanks RichardS for your replay ...

actually the server work very well if I just put Clients[i].stop() in the first loop after reading each client data, but that break my second condition and make clients non simultaneous :(

here is the Client_Registered code
Code: Select allbool Client_Registered(WiFiClient cl)
{
    for(int i=0;i<CLIENTS_NUM;++i)
    {
         if(Clients[i] && cl.remoteIP() == Clients[i].remoteIP()) return 1;
    }
    return 0;
}


for the "INTEGER" sorry it was my fault, it's actually one digit number ( 1, 2, ...) denoting for the client number