TCP simultaneous clients conflicts!!
Posted: Thu Aug 02, 2018 7:18 am
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) :
Client's code (transmitting block):
The problem is that the server is stop responding or stuck in somewhere after receiving data from the first client.
- 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 all
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):
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.