Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By MrOmar
#77538 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.
Last edited by MrOmar on Thu Aug 02, 2018 12:13 pm, edited 1 time in total.
User avatar
By RichardS
#77543 Could you post the code for the Client_Registered() ??

RichardS
User avatar
By RichardS
#77566 I think also client.write() only sends out a byte so the write(INTEGER) seems odd....

Can you post the other code?

RichardS
User avatar
By MrOmar
#77569 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