The TCP keep alive function seems doesn't work

sunweili50
Posts: 8
Joined: Sun Oct 23, 2016 9:25 am

The TCP keep alive function seems doesn't work

Postby sunweili50 » Fri Jan 06, 2017 10:49 pm

I'm writting a tcp client sample based on the ESP8266_RTOS_SDK.
i am using the socket(), connect(),close() ... functions directly instead of the espconn_xxxx() api.
when i set the keep alive parameters for a tcp client :

Code: Select all

   ...
   client_fd= socket();
   ...
   
   int keepAlive = 1; //enable keepalive
     int keepIdle = 10; //60s
    int keepInterval = 5; //5s
    int keepCount = 3; //retry times

   rslt = setsockopt(client_fd, SOL_SOCKET, SO_KEEPALIVE, (void *)&keepAlive, sizeof(keepAlive));
   rslt = setsockopt(client_fd, IPPROTO_TCP, TCP_KEEPIDLE, (void*)&keepIdle, sizeof(keepIdle));
   rslt = setsockopt(client_fd, IPPROTO_TCP, TCP_KEEPINTVL, (void *)&keepInterval, sizeof(keepInterval));
   rslt = setsockopt(client_fd, IPPROTO_TCP, TCP_KEEPCNT, (void *)&keepCount, sizeof(keepCount));
   
   ...
   connect(client_fd);
   ...


it seems that the setsockopt functions does't work.

when the server close the socket , the esp8266 seems does't know that in correct time.
in other words, the recv() don't return -1 in 10+5*3 = 25seconds when the server close socket. the recv() always return -1 in 2minutes.

anybody help,thanks very much !!!

ESP_Xutao
Posts: 134
Joined: Tue Sep 27, 2016 5:42 pm

Re: The TCP keep alive function seems doesn't work

Postby ESP_Xutao » Mon Jan 09, 2017 4:03 pm

Hi:
You can use espconn_regist_time(0;

sunweili50
Posts: 8
Joined: Sun Oct 23, 2016 9:25 am

Re: The TCP keep alive function seems doesn't work

Postby sunweili50 » Mon Jan 09, 2017 7:04 pm

ESP_Xutao wrote:Hi:
You can use espconn_regist_time(0;

you mean i should replace all the POSIX functions with espconn_xxx api?
i don't think this function can used mix with the socket(), connect()....
Last edited by sunweili50 on Mon Jan 09, 2017 7:08 pm, edited 1 time in total.

sunweili50
Posts: 8
Joined: Sun Oct 23, 2016 9:25 am

Re: The TCP keep alive function seems doesn't work

Postby sunweili50 » Mon Jan 09, 2017 7:06 pm

I want to figure out is that this problem is a bug of the tcp library, or is there someting wrong with my code ?

朝花夕拾
Posts: 12
Joined: Fri Mar 10, 2017 9:26 am

Re: The TCP keep alive function seems doesn't work

Postby 朝花夕拾 » Fri Mar 10, 2017 2:37 pm

hi,
could you tell me, Under what conditions ? TCP server automatically disconnect TCP client ;
is it a few minutes ?

Who is online

Users browsing this forum: Sophiasuemy and 7 guests