WiFiClient.connect(server, port) behaves strangely

Hi all,

Maybe I am misunderstanding something, but if I connect to a valid server:

#include <ESP8266WiFi.h>
WiFiClient client;
char* server = "adrianbowyer.com"; // My real domain that exists
.
.
.
if (client.connect(server, 80)) 
{
     ... Returns true, so I end up here as expected
}

But if I connect to an invalid server:

#include <ESP8266WiFi.h>
WiFiClient client;
char* server = "adrianbowyer.comx"; // Dud domain that doesn't exist; no DNS
.
.
.
if (client.connect(server, 80)) 
{
     ... Returns true, so I end up here.  This is not what I would expect.
}

Am I being more than usually stupid?

Best wishes

Adrian

Assuming that the connect function is based on that in the ethernet library, it returns one for success and various negative numbers for different error conditions. All of those are non-zero, which, in the context of your if statement are therefore 'true'.

Thanks!

But afraid that's not it. Both return 1.

(It would help if all the documentation said

if (client.connect(server, 80) == 1)

rather than

if (client.connect(server, 80))

, but that's a separate matter...)

which version of esp8266 Arduino core?

2.4.0

I see that the one on Github (GitHub - esp8266/Arduino: ESP8266 core for Arduino) is 2.5.0-dev (in the master branch), but I'm reluctant to use a dev version for something that will (I hope) go into production.

I asked to check if I look in the right source code. first operation in connect is dns resolving the name. It should fail. I test it later