Closed
Description
When connecting to not responding server/port using WiFiClientSecure
, connection timeout is always around 18s.
However, connection timeout works ok for the WiFiClient
.
When looking at sources, WiFiClient::connect uses a common non-blocking socket connect pattern for receiving the desired timeout. This is not implemented in the start_ssl_client function used by WiFiClientSecure
.
Is there a reason, why connection timeout is not implemented in the start_ssl_client
function?
I've tried copy the initial connection pattern from WiFiClient::connect
pattern to start_ssl_client
and it works ok (unsurprisingly).
Testing code:
#include <WiFiClientSecure.h>
const char* ssid = "SSID "; // your network SSID (name of wifi network)
const char* password = "password"; // your network password
const char* server = "www.howsmyssl.com"; // Server URL
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(115200);
delay(100);
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
WiFi.begin(ssid, password);
// attempt to connect to Wifi network:
int i = 30;
while (WiFi.status() != WL_CONNECTED && --i) {
Serial.print(".");
// wait 1 second for re-trying
delay(500);
}
if(WiFi.isConnected()) {
Serial.print("Connected to ");
Serial.println(ssid);
} else {
Serial.println("Connection failed ");
Serial.println("Restarting.. ");
ESP.restart();
}
WiFiClientSecure secClient;
secClient.setInsecure();
Serial.println("\nStarting secure connection to server...");
uint32_t start = millis();
int r = secClient.connect(server, 440, 5000);
Serial.printf("Connection took: %lums\n", millis()-start);
if(!r) {
Serial.println("Connection failed!");
} else {
Serial.println("Connected!");
secClient.stop();
}
WiFiClient client;
Serial.println("\nStarting unsecure connection to server...");
start = millis();
r = client.connect("192.168.1.3", 500, 3000);
Serial.printf("Connection took: %lums\n", millis()-start);
if(!r) {
Serial.println("Connection failed!");
} else {
Serial.println("Connected!");
client.stop();
}
}
void loop() {
// do nothing
}
Metadata
Metadata
Assignees
Labels
No labels