Cannot connect with TCP client suddenly - NOTconnected

This stuff drives me mad today. While I thought to have a working version of TCP connect last week, it now suddenly stopped working and gives me a ‘NOTconnected’. I stripped it down to the lightweight version (below) - pointing to my local web server - giving me the same.

this call:

   if (client.connected()) {

throws a false. http://10.0.1.4:8000 is def. up and reachable from the core.

Any thoughts ?

– snippet:

TCPClient client;
 
 const char * serverName = "10.0.1.4"; 
 
void setup() {

  Serial.begin(9600);

}

void loop() {

client.connect(serverName, 8000);
     
    if (client.connected()) {
        
        String GetURL = "GET /pushingbox?devid=";
        
            Serial.println("Connected");
            client.println("GET /pushingbox?devid=  HTTP/1.0");
            client.print("Host: ");
            client.println("10.0.1.4");
            client.println("Connection: close"); //just added
            client.println();
            client.flush();
            delay(400);
            client.stop();
            
         }
        else {
            client.flush();
            client.stop();
            Serial.println("NOTconnected");
            
        }  
delay(5000);

}

The client.connect() function returns a boolean upon succes or failure. Perhaps you should try to use that instead of cllient.connected()?

Second suggestion: the WiFi.ping() function can be used to see if a server responds to a ping request. Why don’t you try that to see if your server is still there.

In my own webserver project I’ve encountered several times that my loop was still running, but a ping to my gateway failed. In that situation clients were also not able to connect, so I now do an occasional ping of my gateway to see if the Spark Core is still functioning in its proper state.

Try changing that to

IPAddress serverName(10,0,1,4);

Thanks MDMA, that worked. Looks like I can only connect on IP, not on Server Name anymore (while I think that worked before, ie:

IPAddress serverName(173,194,44,80) // WORKS

const char * serverName = “www.google.com”; // DOES NOT WORK

I flashed the core to factory reset. Its my local network, dns etc all works.

Any thoughts?

thx,

Leon