How to debug TCPClient connect() fails

Hi, Im having trouble with TCPClient intermittently not connecting to a server and am trying to dig deeper into how/why the connect() is failing. Im logging the packets of the connection on my firewall and I see the SYN go out from the spark and then two SYN ACKs coming back from the remote server and then nothing back from the spark and my app shows “connect failed”, TCPClient::connect returned a 0 for connected. When 9 times out of 10 it does connect, after the first SYN,ACK comes back, spark responds with an ACK and its now connected and my app continues with its TCP connection just fine.

Ive already bypassed the DNS possibility, I’m sending connect() an IP address and not a hostname.

So id like to debug this further to see why TCPClient isn’t able to set up and connect the socket sometimes. Can I just #include “spark_wiring_tcpclient.cpp” in my project and add debugging code to it? How do I enable DEBUG flag in the code and where does it output the debug messages? I tried including it but I must be missing something about how to tell the compiler to use my version and not the “internal” one from firmware.

Thanks for any help.

Are you sure you are reading all the data from server? Not reading all the data will eventually make the connection fail for sure.

If you want to put debug stuff in the client, I think you will have to compile locally with make and gcc.

1 Like