RTCS TCP/IP

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

RTCS TCP/IP

572 Views
wyao75
Contributor I

Hi all,

I use K60 and MQX 4.1

I'd like to use socket receive TCP/IP packet every 100ms.

computer as server (device A)and k60 as client(device B).

Now K60 can receive data every 100ms .

My question is if device A disconnect and maybe 2mins later it reconnect, but the k60 can't receive data. I try to check the connection state if connection fail it will reconnect, but still not work.

  socket_init();

   uint16_t rlen=sizeof(raddr);

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

   while(1)

   {

     k=RTCS_selectall(100);

     if (i!= RTCS_OK)

     {

       shutdown(sock_list[0],FLAG_ABORT_CONNECTION);

       socket_init();

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

     }

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

}

0 Kudos
3 Replies

341 Views
Carlos_Musich
NXP Employee
NXP Employee

Hi!

You can use the following instruction to check the link status: result = ipcfg_get_link_active(BSP_DEFAULT_ENET_DEVICE);

Then shutdown socket and don't reconnect until link is up again: while(!ipcfg_get_link_active(BSP_DEFAULT_ENET_DEVICE)) {};

Regards,

Carlos

0 Kudos

341 Views
wyao75
Contributor I

HI

I want to know how to check the state of TCP/IP connection rather than the state of Ethernet link.

I use computer as server and k60 as client .

In TCP/IP protocol, computer(server) should listen first and then k60 (client) connect it.

I want to know if k60 connect first and the computer listen after 2 min. k60 how to reconnect?

0 Kudos

341 Views
Carlos_Musich
NXP Employee
NXP Employee

Hi,

You can use Connection Timeout option.

To set this option you need function setsockopt() and the option parameter is OPT_CONNECT_TIMEOUT.

You can find it documented in MQX_RTCS_User_Guide.pdf. It is located in installation path:

C:\Freescale\Freescale_MQX_4_2\doc\rtcs

Regards,

Carlos

0 Kudos