This is the esp32 arduino code:
Code: Select all
...
WiFiServer server(port);
void serverStartup(){
server.begin();
//server.setTimeout(5);
delay(1000);
Serial.println("Waiting for client...");
WiFiClient client = server.available();
if (client) { // if you get a client,
Serial.println("New Client."); // print a message out the serial port
while (client.connected()) { // loop while the client's connected
client.setTimeout(5); // timeout does not seem to work
//Serial.print("Client connected");
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
printf("%d",c); // print it out the serial monitor
}
}
client.stop();
Serial.println("Client Disconnected.");
}
Serial.println("Ending server.");
server.end();
}
void setup()
{
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
WiFi.config(myIP,gateway,subnet);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop()
{
delay(1000);
serverStartup();
}
Code: Select all
var net = require('net');
var client = net.connect({ host: "192.168.1.127", port: 1234 }, doNothing);
function doNothing(){
console.log("Doing nothing.");
Code: Select all
$ node simpleclient.js
Doing nothing.
Code: Select all
WiFi connected
IP address:
192.168.1.127
Waiting for client...
Ending server.
Waiting for client...
Ending server.
Waiting for client...
New Client.
I would have expected that the esp32 server disconnects after the timeout of 5 seconds.
I tried out various things like setting the timeout on the server (which has the same effect) or just after the client was created (which resulted in an error (because the client was not connected?). I also checked that the return code of setTimeout is non-negative.
But i never saw a timeout.
In fact this looks very similar to https://github.com/espressif/arduino-esp32/issues/330, but that issue seems to be closed...
(I am using platformio on visual studio code and have just updated esp32 arduino just today to 0.10.0)
Any suggestions?
Gregg