Skip to main content
Visitor II
November 14, 2022
Question

How to check connection alive in LWIP?

  • November 14, 2022
  • 6 replies
  • 4437 views

Hello,

I am using STM32H743 and imported the sample project LwIP_HTTP_Server_Netconn_RTOS. Is there anyway to indicate the TCPIP is still alive or not in case the ethernet cable is disconnected?

Thanks

    This topic has been closed for replies.

    6 replies

    Graduate II
    November 15, 2022

    The TCP connection connected until it is... disconnected. The Ethernet link state is not directly related to TCP connection state and it doesn't tell anything about whether the other IP device is reachable. For that purpose sometimes ICMP ping can be used.

    AFung.1Author
    Visitor II
    November 15, 2022

    Thank you for your answer.

    Do you mean to send ping from the client to the STM TCPIP server? This doesn't work to me because I need the STM to detect the disconnection itself so that it can shut off some functions. Do you have any idea about it?

    Thanks.

    AFung.1Author
    Visitor II
    November 15, 2022

    In err.h, there are many error status such as

    /** Not connected.      */

     ERR_CONN  

    /** Connection aborted.   */

     ERR_ABRT    = -13,

    /** Connection reset.    */

     ERR_RST    = -14,

    /** Connection closed.    */

     ERR_CLSD  

    When the connection is disconnected by client, the ERR_CLSD is returned. However, there is nothing returned when the connection is disconnected by unplug the ethernet.

    Explorer II
    November 15, 2022

    Disconnection is done at physical level, TCP is a protocol at a very higher level. TCP is not aware of physical state and can't report this information. You have to check at physical level for disconnection (Looks like there is a callback for this)

    Graduate II
    November 16, 2022

    > send ping from the client to the STM TCPIP server? This doesn't work to me

    Ping is not related to your TCP connection and can be sent by both sides.

    > I need the STM to detect the disconnection itself so that it can shut off some functions

    Disconnection of what? Ethernet link or TCP connection?

    > there is nothing returned when the connection is disconnected by unplug the ethernet

    Ethernet link state is managed by a code that is not related to TCP in any way and is detected almost immediately. On the other hand, TCP connection will time out only after 2 hours.

    AFung.1Author
    Visitor II
    November 16, 2022

    Hello Piranha,

    It should be the disconnection of the ethernet link. I can get the TCP disconnected with no problem and the ERR_CLSD is returned right away when the client close the TCP connection. However, if I unplug the ethernet cable intentionally, no status is returned even there is no ERR_CLSD. So I would like the STM to detect this kind of disconnection. Thanks for you help.

    Andy