Wi-Fi connection timeout?

Hello everybody,

I’m connecting to some TCP servers using my new LinkIt ONE and the LWiFiClient class.

The .connect() method returns 1 if it connects to the IP address I specified, but if the IP address doesn’t exists or doesn’t accept connections (for example, if the server is down) it doesn’t return anything and the code gets stuck there. I assume it should timeout then return 0 as per the documentation.

Example:

int conn = c.connect("192.168.1.5", 8080);
if(conn == 1){
     ...
} else {
     ...
}

If 192.168.1.5 is down, c.connect doesn’t return anything and I can’t get into the else branch.

Any ideas on how to solve this?

Thank you

Update: It looks like it’s working and it was only my fault. I had a boolean variable named “connected” that conflicted with the LWifiClient which also has a .connected() function.

Everything is working fine now.

nice~ :smiley:

I have problems trying to do the opposite now: I want the LinkIt to be a TCP server and receive commands from clients.

This is my code, based on the mediatek documentation (sadly there are no working examples), but I can’t understand why it doesn’t work.

It connects to the Wi-Fi just fine, yet it refuses all the connections by the clients.

[code]#include <LWiFi.h>
#include <LWiFiClient.h>
#include <LWiFiServer.h>

#define AP_NAME “TP-LINK”
#define PASSWORD “mypassword”
#define PORT 8080

boolean first = true;

LWiFiClient c;
LWiFiServer server(8080);

void setup() {
Serial.begin(9600);
LWiFi.begin();
LWiFi.connectWPA(AP_NAME, PASSWORD);
Serial.println(“Connected to Wi-Fi!”);
server.begin();
}

void loop() {
if(first){
c = server.available();
first = false;
}
if(c.available()){
char ch = c.read();
Serial.print(ch);
}
delay(1000);
}[/code]

Any ideas on how to make this work? Thank you