cancel
Showing results for 
Search instead for 
Did you mean: 

How to check connection alive in LWIP?

AFung.1
Associate II

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

6 REPLIES 6
Piranha
Chief II

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.1
Associate II

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.1
Associate II

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.

Nikita91
Lead II

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)

Piranha
Chief II

> 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.1
Associate II

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