|
 UltimaSerial
Windaq Add-ons
UltimaWaterfall
XChart
FFT1024

Lessons |
|
Please finish lwIP TCP
workshop before trying this
one
Keepalive is an important feature in TCP
connection to make sure we don't lose the link. For more info regarding
keepalive in TCP, please visit
Wikipedia.
- Use the codes in lwIP TCP
workshop to create a TCP
echo server first
- In lwipopts.h, add "#define LWIP_TCP_KEEPALIVE
1"
-
In tcp.h, modify the timing parameters according
to your application. We chose the
following for shorter time.
-
TCPKEEPINTVL_DEFAULT
to 3000UL (default was 7200000UL)
-
TCP_KEEPCNT_DEFAULT
to 1000UL (default was 75000UL)
-
TCP_KEEPCNT_DEDAULT to
3U (default was 9U)
-
Bring lwip_socket definition from sockets.c to sockets.h so that
we can use it in the TCP thread
-
Add the follow lines after
lwip_socket: struct lwip_socket
*sock=get_socket(lSocket); struct netconn* myconn =
sock->conn; myconn->pcb.tcp->so_options |=
SOF_KEEPALIVE;
-
Due to a bug in lwIP, the following patch
is necessary until next release of lwIP, refer to
https://savannah.nongnu.org/bugs/?25629:
-
In src/core/tcp_out.c:tcp_keepalive(),
locate the following lines tcphdr->ackno =
htonl(pcb->rcv_nxt); TCPH_FLAGS_SET(tcphdr, 0);
tcphdr->wnd =
htons(pcb->rcv_ann_wnd); tcphdr->urgp = 0;
-
Replace with: tcphdr->ackno =
htonl(pcb->rcv_nxt); TCPH_FLAGS_SET(tcphdr, TCP_ACK); tcphdr->wnd =
htons(pcb->rcv_ann_wnd + 1); tcphdr->urgp = 0;
-
Add a call to tcp_tmr() every 250ms
-
Build and run
-
Telnet to it
-
To verify keepalive, run Wireshark.
If you don't type anything for 3 seconds (defined by
TCPKEEPINTVL_DEFAULT), keepalive packet be sent out once a second
(defined by TCP_KEEPCNT_DEFAULT) will by lwIP, and the PC will ACK the keepalive packet.
-
If you remove the ethernet cable, thus the
lwIP will not receive the ACK from the PC. After 3 tries (defined by TCP_KEEPCNT_DEDAULT), lwIP will close the connection
Find out how to upgrade to the latest lwIP
Last update: 04/08/10 |