AnsweredAssumed Answered

OPT_CONNECT_TIMEOUT not work

Question asked by 玮 姚 on Aug 21, 2015
Latest reply on Aug 25, 2015 by 玮 姚

HI all, I use K60 and MQX4.2.

In TCP/IP protocol, K60 as client and computer as server.  K60 can receive data and send data every 1 second.

my question is when computer disconnect  TCP connection and reconnect after 10 seconds , k60 can't receive data and computer also can't receive data

it means reconnect fail. .

 

I modify the OPT_CONNECT_TIMEOUT, OPT_SEND_TIMEOUT,OPT_TIMEWAIT_TIMEOUT, but still not work .

 

this is my code

 

   uint32_t opt_value=TRUE;

   uint32_t time_out=10000;

   uint32_t send_time_out=10000;

   uint32_t wait_time_out=10000;

   uint32_t opt_length = sizeof(uint32_t);

   sock_list[0]=socket(AF_INET,SOCK_STREAM,0);//创建TCPIPsocket

   setsockopt(sock_list[0],SOL_TCP,OPT_SEND_TIMEOUT,&send_time_out,opt_length);

   setsockopt(sock_list[0],SOL_TCP,OPT_CONNECT_TIMEOUT,&time_out,opt_length);

   setsockopt(sock_list[0],SOL_TCP,OPT_TIMEWAIT_TIMEOUT,&wait_time_out,opt_length);             

   laddr.sin_family=AF_INET;

   laddr.sin_port=8000;

   laddr.sin_addr.s_addr=INADDR_ANY;  

   bind(sock_list[0],&laddr,sizeof(laddr));//绑定TCPsocket;

   raddr.sin_family=AF_INET;

   raddr.sin_port=8000;

   raddr.sin_addr.s_addr=IPADDR(192,168,50,200); 

   setsockopt(sock_list[0],SOL_TCP,OPT_RECEIVE_NOWAIT,&opt_value, opt_length);

   connect(sock_list[0],(struct sockaddr *)&raddr,rlen);

   while(1)

   {        

        RTCS_selectall(100);

        recv(sock_list[0],buffer_tcp_recv,30,0);

        send(sock_list[0],buffer_tcp_send,16,0);

        if (buffer_tcp_send[9]==0x03)

    

     _time_delay(1000);

   }

Outcomes