I have a project that connects to a TCP socket server.
I have realized that TCPClient.connect() function always returns true. No matter if server exists or not. Do am I missing something? Or is it really an incorrect behaviour?
DeviceOS: v1.0.1
3rd Party Sim
#define TCP_SERVER "noMatterWhatIsAddedHere.alWaysReturns.true"
#define TCP_PORT 6666
TCPClient tcp_client;
bool doOnlyOnce = false;
// Connects to a cellular network by APN only
STARTUP(cellular_credentials_set("m2m.movistar.es", "", "", NULL));
// define system mode
SYSTEM_MODE(SEMI_AUTOMATIC);
//enable system thread
SYSTEM_THREAD(ENABLED);
// setup() runs once, when the device is first turned on.
void setup() {
// Put initialization like pinMode and begin functions here.
//debug
Serial.begin(9600);
}
// loop() runs over and over again, as quickly as it can execute.
void loop() {
// The core of your code will likely live here.
if (Particle.connected() == false)
{
Particle.connect();
}
else
{
if (!doOnlyOnce){
Serial.printlnf("Connecting to... %s:%d", TCP_SERVER, TCP_PORT);
if (tcp_client.connect(TCP_SERVER, TCP_PORT))
{
Serial.println("TCP socket connected!"); // <<<<<< It does not matter where it connects. Always is entered into this condition
}
else
{
Serial.println("TCP socket connection error"); // <<<<<< Never entered into this condition. It does not matter if server does not exist
}
doOnlyOnce = true;
}
}
}