I want to create a simple Wifi TCP server by ESP8266 in Arduino IDE. But I have a big problem: when I send a character or string from client I can\'t receive it on the server.>
In the loop, you are closing the client connection as soon as it is established deleting the WiFiClient
object.
In order to keep the connection open you could modify the loop like this :
WiFiClient client;
void loop()
{
if (!client.connected()) {
// try to connect to a new client
client = server.available();
} else {
// read data from the connected client
if (client.available() > 0) {
Serial.write(client.read());
}
}
}
When client is not connected it tries to connect one and when a client is connected, it reads incoming data.