[lwip-users] TCP Disconnect Detection lwIP V1.2

923 views
Skip to first unread message

Gurpal Gill

unread,
Mar 30, 2009, 1:08:04 PM3/30/09
to lwip-...@nongnu.org
Hello,
 
I'm wondering how to detect that a TCP connection has been closed? Also, if a connection were to get disconnected via a power outage (simulated by disconnecting the ethernet cable from the device)? Currently I transmit a byte of data every 15secs of no activity and when I get an error I close the connection. I need a better way since the application on the other end has to process the byte that I'm sending which causes problems. I'm using lwIP with the xilinx tools (S3ADSP1800A eval board). Just a note, I'm using lwIP in non blocking mode so the read command either returns -1 or the number of bytes read. Any help would be appreciated.
 
Regards,
 
Gurpal Gill

Bill Auerbach

unread,
Mar 30, 2009, 1:28:29 PM3/30/09
to Mailing list for lwIP users

Some suggestions:

 

1)      Use 2 connections (ports) – one for the real connection and one for the 15S ping.

2)      Use TCP_KEEPALIVEs, but you have to change the default TCP_KEEPALIVE time on the other end since the default is a long time and it won’t notice the lost connection.

3)      Use UDP and send a “ping” for checking the device.

 

I use the latter using a 5S sending period with a UDP broadcast and it works pretty well for the PC (Win32) app to see the lwIP devices come and go.  This ping also gives me the opportunity to send out the device’s IP address in the payload so that the PC can make a connection (TCP) once it sees the device.

 

Bill

gold...@gmx.de

unread,
Mar 30, 2009, 3:30:12 PM3/30/09
to Mailing list for lwIP users
Questions like this one are often asked here. In fact, TCP is not really
helpful here. There are a few parameters to tweak to make TCP detect
connection errors earlier, but most of them have some side-effects so
that you really have to know what you are doing.

What you are doing is already the best solution, I guess: design the
communication protocol in a way that always at least a little data is
being sent so that the other end can detect when that data doesn't come.

Regarding the connection closure, that depends on the protocol being
used: raw API returns a null pbuf, the other APIs have other means to
tell you the remote side closed - but all this happens only after large
timeouts when using the default TCP parameters.

Simon

> ------------------------------------------------------------------------
>
> _______________________________________________
> lwip-users mailing list
> lwip-...@nongnu.org
> http://lists.nongnu.org/mailman/listinfo/lwip-users

_______________________________________________
lwip-users mailing list
lwip-...@nongnu.org
http://lists.nongnu.org/mailman/listinfo/lwip-users

Reply all
Reply to author
Forward
0 new messages