In my TCP/IP project , I can not modify keepalive times&period of a socket by modify ipconfigTCP_KEEP_ALIVE_INTERVAL. need help! thanks!
We would like to help, but unfortunately your post doesn’t say what the
problem is. For example, can not modify could mean keepalive isn’t
working at all, keepalive is working but you can’t change the period,
you can change the period but the period is not accurate…or simply
that the file is read only so you can’t save changes. Please help us
thanks for your answers and sorry for my question. My keepalive is working (in socket client and server ), the period is about 20s , but I modify ipconfigTCP_KEEP_ALIVE_INTERVAL to 2 or 3 or 8 or 20 or … ,the period is about 20s always. In LWIP ,I can change it by modify some parameters. And the other parameter “ipconfigTCP_HANG_PROTECTION_TIME” is 10 now , I modify it ,but no use for anything. (sorry for my english)
It sounds like a problem with compiling your project.
In the demo projects,
ipconfigTCP_KEEP_ALIVE_INTERVAL is defined as 20 seconds. When you observe that the actual keep alive messages are sent every 20 seconds, it looks like
FreeRTOS_TCP_IP.c doesn’t see your new value.
You should make the setting in your
FreeRTOSIPConfig.h. Make sure that the include path for the compiler points to the proper
Advice: never put private files into the public include directories, such as
You could write the following in your
#warning setting keep-alive #define ipconfigTCP_KEEP_ALIVE_INTERVAL 120
and make sure the the compilere sees the #warning
Which platform are you using? In some Xilinx SDK versions changing a
header file necessitates a complete clean and rebuild for the new value
to get used.
My platform is stm32f107RC + keil mdk 5.22 and compiler is v5.06(update 4) .
I do your test,and see #warning … so …
I set ipconfigTCP_KEEP_ALIVE_INTERVAL =40 , keep alive messages is 40s
I set ipconfigTCP_KEEP_ALIVE_INTERVAL =30 , keep alive messages is 40s
I set ipconfigTCP_KEEP_ALIVE_INTERVAL =20 , keep alive messages is 20s
I set ipconfigTCP_KEEP_ALIVE_INTERVAL =15 , keep alive messages is 20s
I set ipconfigTCP_KEEP_ALIVE_INTERVAL <10 , keep alive messages is 20s
I set ipconfigTCP_KEEP_ALIVE_INTERVAL =60 , keep alive messages is 60s
I set ipconfigTCP_KEEP_ALIVE_INTERVAL =50 , keep alive messages is 60s
and the period of keepalive is variable ， about 2s~10s
Good, so changing the value of
ipconfigTCP_KEEP_ALIVE_INTERVAL does make a difference.
What you observe is that the actual times are being rounded up to a multiple of 20 seconds.
That is caused by the function
prvTCPNextTimeout(), which let’s the socket ‘sleep’ for 20 seconds when it is idle.
If you want, I will prepare a patch in which this sleeping time will be configurable.
Thanks. Could you do a new version to improve and perfect it and Release new version to all ? I think this function is very important for checking socket ok or not.
I hope get your patch at first
My e-mail: firstname.lastname@example.org
And this TCP/IP lib is better than LWIP. Thanks for your work!
Normally I would set the keep-alive period
ìpconfigTCP_KEEP_ALIVE_INTERVAL at least 60 seconds. Only when a keep-alive message is not responded to (and
ucKeepRepCount increases), the intervals will be much shorter. After three times now answer, the socket will be forcefully closed.
I have sent you an email with patched source code. If you test it we can make it an official change.
Note that for an embedded TCP application, the keep-alive messages are essential. It avoids that sockets stack in a connected state for hours, thus occupying valuable resources.
The keep-alive messages do not always work, some routers might refuse to pass them through.