STM32F767ZI client socket hanging on connect

I am using an Nucleo STM32F767ZI with MBED OS 6.9.0, and I am running into issues with TCPSocket::connect() reporting -3004 (NSAPI_ERROR_NO_CONNECTION) error which is “not connected to a network.” This is despite the fact that “network.connect()” and “” all report no error. (see code below).

I am checking if errors occur at each stage of the process which are all reporting that there are no issues. If I run the ST as a server (i.e. bind, accept, etc… are all working as expected), I can use my computer to send/recv information from the ST without issue. I only run into problems when trying to run the ST as a client.

When the code gets to “client.connect(server_address)” it hangs for a few seconds and reports the error.

    printf("Ethernet client example\n");
    nsapi_error_t conn_error = network.connect();

    SocketAddress server_address("", 1234);

    TCPSocket client;
    conn_error =;

    conn_error = client.connect(server_address);

    if (conn_error == 0)
        printf("Connection Open!\n");
        return -1;

I am using PlatformIO, but I also tried MBED Studio with MBED OS 6.17.0 and the behavior is the same. Am I doing anything wrong, or is there possibly a bug I don’t know about? Any insight would be much appreciated.


usuall is good to start with official example of the API TCPSocket - API references and tutorials | Mbed OS 6 Documentation

I tried your code without significant changes and it is working as expected. Here is my setup

  • Nucleo-F767ZI
  • KeilStudioCloud
  • MbedOS 6.17
  • PC TCPserver app - Network Tool Connection (from MS store)
  • PC server IP address assigned by router
#include "mbed.h"
#include "EthernetInterface.h"

// Network interface
EthernetInterface network;

// Socket demo
int main()
    // Bring up the ethernet interface
    printf("Ethernet socket example\n");
    nsapi_error_t conn_error = network.connect();

    SocketAddress server_address("", 8080);

    TCPSocket client;
    conn_error =;

    conn_error = client.connect(server_address);

    if (conn_error == NSAPI_ERROR_OK) printf("Connection Open!\n");

    // Close the socket to return its memory and bring down the network interface
    // Bring down the ethernet interface

PC log from the app:

6/1/2023 9:11:16 PM  New connection from
6/1/2023 9:11:16 PM  Remote connection disconnected. (

I believe the issue will be on PC side, especially IP address settings.

BR, Jan

1 Like

Thank you for taking the time to run a test. Your recommendation to look at the PC side was the trick. It was a firewall setting preventing inbound connections.

1 Like