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