How to have tcp server socket detect client gone

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Given the snip/tcp_server example, how can we learn that the client has gone.

For example a phone client connects to the server and then the WLAN link is shut off on the phone.

The socket continues to wait in wiced_tcp_receive (or timeout if set) but I can find no way to learn that the client is gone.

If the client does a clean disconnect, the server loops back around to wiced_tcp_accept.

How do I make it do this when the WLAN link is shutoff (and similar unplanned disconnects from client)?

Using 3.0.1 or 3.1.0

0 Likes
6 Replies
AxLi_1746341
Level 7
Level 7
10 comments on KBA 5 comments on KBA First comment on KBA

davidep wrote:

Given the snip/tcp_server example, how can we learn that the client has gone.

For example a phone client connects to the server and then the WLAN link is shut off on the phone.

The socket continues to wait in wiced_tcp_receive (or timeout if set) but I can find no way to learn that the client is gone.

Use TCP keep alive.

You can reference apps/snip/tcp_server/tcp_server.c for the usage of wiced_tcp_enable_keepalive()

0 Likes
Anonymous
Not applicable

Unfortunately I'm using an old version of WICED 3.0.1 which does not support keepalive.

0 Likes

davidep wrote:

Unfortunately I'm using an old version of WICED 3.0.1 which does not support keepalive.

It's nothing to do with SDK version.

If you are using lwIP, keepalive is supported in WICED 3.0.1.

If you are using NetX/NetX_Duo, wiced_tcp_enable_keepalive() returns WICED_TCPIP_UNSUPPORTED

even with latest SDK.

Anonymous
Not applicable

I've moved on to a UDP implementation for this project. But I'll keep that in mind. I think the device platform preferred ThreadX/NetX for some reason.

0 Likes
Anonymous
Not applicable

Hi,

My Tcp server (wifi module) want to receive the data from uart then it will check for client(webpage) and transmit the data to the webpage...

But if no data has been received in the uart for more than 2 minutes my tcp server getting disconnected and webpage is showing "could not connect to server"...

can I use wiced_tcp_enable_keepalive()  to keep the server enable for long time..If so how can i change from NetX/NetX_Duo to lwIP..

please help me to solve this issue..

Thank you!!!

0 Likes

kaviyaa wrote:

Hi,

My Tcp server (wifi module) want to receive the data from uart then it will check for client(webpage) and transmit the data to the webpage...

But if no data has been received in the uart for more than 2 minutes my tcp server getting disconnected and webpage is showing "could not connect to server"...

can I use wiced_tcp_enable_keepalive()  to keep the server enable for long time..If so how can i change from NetX/NetX_Duo to lwIP..

please help me to solve this issue..

Thank you!!!

If your problem happens when wiced_tcp_enable_keepalive() is not called at all, then it's nothing to do with wiced_tcp_enable_keepalive.

0 Likes