I don't know what the problem is but if we do not create WiFiClient for every request just like the example doing, then we can not get continues response from the TCP Server.
for example:
#include <ESP8266WiFi.h>
const char* ssid = "team";
const char* password = "team";
const char* host = "192.168.31.113";
WiFiClient client;
void setup() {
Serial.begin(115200);
delay(10);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
int value = 0;
void loop() {
delay(1000);
++value;
if (!client.connected()){
Serial.print("connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
const int httpPort = 1234;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
}
// This will send the request to the server
//client.write("\xFE\xEF\x0E\xE2\x06\xDB\x48\xB4\xB0\x04\x00\xA2\x00\x04\x16\x1C\xB4",17);
client.write("hello\r\n");
client.flush();
delay(500);
// Read all the lines of the reply from server and print them to Serial
while(client.available()){
//String line = client.readStringUntil('\r');
Serial.print(client.read(),HEX);
Serial.print(" ");
}
Serial.println();
Serial.println("closing connection");
}
if we use other program like python, everything responses well,so server side should be ok, but if we change to ESP 12-E board as TCP client, and use the code above, the response come randomly. it seem the 80% response has been lost, mean while the server side gives all the response successfully return.
what can be the problem?
thanks.