TCPClient connect() always fails

EDIT: please ignore for now. There seems to be a side-issue.

I have a Spark Core and OSX on the same WPA2 Personal WiFi network. Sample code works correctly.

In my actual project, when I try to call connect() using the correct IPAddress and port parameters. The connect() call always returns 0. I have actually tracked down to the TCPClient class implementation code, in TCPClient::connect(IPAddress ip, uint16_t port) function, this block always hits:

if(socket_connect(_sock, &tSocketAddr, sizeof(tSocketAddr)) < 0)
_sock = MAX_SOCK_NUM;

  return 0;


Additionally, when this happens the LED on the Spark Core starts flashing green and stays flashing. I have to press the RST button on the board to get it out.

The IP address of the server Spark Core is trying to connet() is, port number is 50148.

I have tried to give enough delay before attempts of connect() calls (giving it 70 seconds) because in another thread it is mentioned that connect() call might block for 60 seconds. However, the added delay is not helping, either. It still does not connect.

Is anyone seeing similar issue as I am seeing, or is the problem likely in the way I am calling connect()?

1 Like