If not, and you just wish to received a connection request later from the server, let says an hour later, then you need to implement a server on ESP side too, which is the goal of client.available(). But I don't see any server code here.
You're right, I want to send from MLServer at a later time and now tried to implement a server instead but I don't get any indata so obviously I'm doing something wrong! Can it be that both MLServer and the ESP server can listen on the same port ?!.
I appreciate If You could point me in the right direction. I've read forum back and forth but can't figure out how to get it work. My present code :
#include <ESP8266WiFi.h>
const char* ssid = "**********";
const char* password = "***************";
const int Port = 23;
const char* host = "192.168.1.30";
String InputString;
// Use WiFiClient class to create TCP connections
WiFiClient client;
WiFiServer Server(Port);//listen on port 23
void setup() {
Serial.begin(115200);
delay(1000);
// We start by connecting to a WiFi network
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());
}
void loop() {
if (!client.connect(host, Port)) {
Serial.println("connection failed");
// return;
}
else {
Serial.println("Sending ...");
client.print("TEST DATA TO MLServer\r\n");
delay(100);
// yield();
}
if (!client.connect(host, Port)) {
Serial.println("connection failed");
// return;
}
else {
//*********************************************************
//Connected to MLServer waiting for incoming data
//*********************************************************
//Server
client = Server.available();
if (client) {
Serial.println("Recieving ...");
while (client.connected()) {
while (client.available()) {
String line = client.readStringUntil('\r');
delay(10);
Serial.println(line);
line = "";
}
}
// client.stop();//???????????
}
}
delay(3000);
}
Regards Håkan