2 years, 1 month ago.

How to reconnect to TCPSocket or TCPSocketConnection Server

Hi, How can I reconnect to a TCP Server with TCPSocket once the connection is dropped(Server shutdown or someone pulled out the ethernet cable). I'm using nucleo STM32F429

1 Answer

2 years, 1 month ago.

I did something related to this using the Wiznet Ethernet stack. You won't get notified if the far-end disconnects using TCP but imagine you did some sort of keep-alive or other method to know if the connection needed to be reset...

Here is a snippet of code where I did a restart.

TCPSocketServer server;
TCPSocketConnection client1;

...
    {
        if(conn1) {
            client1.disconnect();
            client1.close();
            conn1=false;
        }
        server.close();
    }
...
    ethernet.disconnect();
    int ret = ethernet.init(boardInfo.myMAC,IP_Addr,IP_Subnet,IP_Gateway);