RTCS TCP server socket doesn't accept the connection after disconnecting client 2 times

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

RTCS TCP server socket doesn't accept the connection after disconnecting client 2 times

跳至解决方案
1,473 次查看
pravinfalcao
Contributor II

Hi,

I have a TCP-IP server with two clients respectively on Port 81 and Port 82. Interesting thing is when I disconnect the client and reconnect, it works fine for exactly two times. However after trying to connect 3rd time, 'RTCS_selectset' throws an error message 'RTCS_SOCKET_ERROR' and connection fails permanently until I jump to RTCS/TCP-IP socket initialization.

However in field application, disconnection is frequent and I can not restart my K70 board if this happens. Again assume when Port 81 failed permanently after above scenario, Port 82 is still working fine with send-receive as it has not been disconnected - reconnected for 2 times. Can anyone help me in this?

E.g. One scenario

Port 81 -  Connect (works) - Disconnect - Connect (works) - Disconnect - Connect (doesn't works). == Port 81 dead until re initialization of RTCS/TCP  ==

Port 82 - Connect (works) - No Action    - No Action           - Disconnect - Connect (works)            - No Action  -  Disconnect - Connect (doesn't works). == Port 82 dead until re initialization of RTCS/TCP  ==

标签 (1)
标记 (2)
1 解答
850 次查看
Carlos_Musich
NXP Employee
NXP Employee

Hi Pravin,


Probably you are setting a small number of sockets and the socket timeout is too long. Therefore, if you close all the sockets you have available and you don't wait until their timeout expires you will not be able to use another socket.


You can use function setsockopt() to manage sockets timeouts. These timeouts are declared in tcp_prv.h on the RTCS library project.

#define TCP_MSL           120000L  /* Maximum Segment Lifetime; the
                                      longest time that a packet can
                                      travel in the Internet (2 min) */

#define TCP_WAITTIMEOUT (2 * TCP_MSL)  /* timeout for TIME_WAIT state, defined

                                      as 2 * MSL (4 min) */

#define TCP_SENDTIMEOUT_MIN   100000L  /* as per RFC1122 4.2.3.5 */

#define TCP_OPENTIMEOUT_MIN   180000L  /* as per RFC1122 4.2.3.5 */

But you can override these values with setsockopt().

You can also increase the number of sockets. It is possible customize runtime RTCS configuration before call the function RTCS_create() just as the web_hvac does in the C:\Freescale\Freescale MQX 4.1\demo\web_hvac\RTCS.c file.

/* runtime RTCS configuration */

_RTCSPCB_init = 4;

_RTCSPCB_grow = 2;

_RTCSPCB_max = 20;

_RTCS_msgpool_init = 4;

_RTCS_msgpool_grow = 2;

_RTCS_msgpool_max = 20;

_RTCS_socket_part_init = 4;

_RTCS_socket_part_grow = 2;

_RTCS_socket_part_max = 20;


I hope this helps.



Best regards,

Carlos

Technical Support Engineer

在原帖中查看解决方案

3 回复数
851 次查看
Carlos_Musich
NXP Employee
NXP Employee

Hi Pravin,


Probably you are setting a small number of sockets and the socket timeout is too long. Therefore, if you close all the sockets you have available and you don't wait until their timeout expires you will not be able to use another socket.


You can use function setsockopt() to manage sockets timeouts. These timeouts are declared in tcp_prv.h on the RTCS library project.

#define TCP_MSL           120000L  /* Maximum Segment Lifetime; the
                                      longest time that a packet can
                                      travel in the Internet (2 min) */

#define TCP_WAITTIMEOUT (2 * TCP_MSL)  /* timeout for TIME_WAIT state, defined

                                      as 2 * MSL (4 min) */

#define TCP_SENDTIMEOUT_MIN   100000L  /* as per RFC1122 4.2.3.5 */

#define TCP_OPENTIMEOUT_MIN   180000L  /* as per RFC1122 4.2.3.5 */

But you can override these values with setsockopt().

You can also increase the number of sockets. It is possible customize runtime RTCS configuration before call the function RTCS_create() just as the web_hvac does in the C:\Freescale\Freescale MQX 4.1\demo\web_hvac\RTCS.c file.

/* runtime RTCS configuration */

_RTCSPCB_init = 4;

_RTCSPCB_grow = 2;

_RTCSPCB_max = 20;

_RTCS_msgpool_init = 4;

_RTCS_msgpool_grow = 2;

_RTCS_msgpool_max = 20;

_RTCS_socket_part_init = 4;

_RTCS_socket_part_grow = 2;

_RTCS_socket_part_max = 20;


I hope this helps.



Best regards,

Carlos

Technical Support Engineer

850 次查看
pravinfalcao
Contributor II

Hi Carlos,

Thanks a lot!! It works!!!

Best Regards,

Pravin

0 项奖励
850 次查看
Carlos_Musich
NXP Employee
NXP Employee

Happy to help Pravin.

Regards,

Carlos

0 项奖励