AnsweredAssumed Answered

MQX rtcs client TCP connect return 5705

Question asked by Jamate Maholu on Mar 2, 2014
Latest reply on Mar 20, 2014 by gorakk

Hi I am trying to create application with TCP client in a TWR - K60n12 using MQX.

I have a problem with connection. Function  connect(....) return :5705. I guess it is timeout because it takes long time...

Do you know what doest it mean (5705)?

Could you please look into code if I made a error in code?

Is it necessary to modify HW jumper on the TWR kit?

I have a C# (server) application which is waiting on specific port (60000) to connection (from TWR K60n12).

I am using static IP address TWR 192.168.1.2  PC: 192.168.1.5

 

Thank you very much for your HELP. I have spent long days on this problem.

 

 

   IPCFG_IP_ADDRESS_DATA ip_data;

   _enet_address           enet_address;  

 

   //server communication

   uint_32 sock,listensock;

   sockaddr_in addr;

     

   uint_32 error = RTCS_create();

  

   char str[] = "\nHello Worldcmkdmckldsnvndsvkjdsnvkjsnvkjkjvnskjnvkjdsnvkjdsnkjvndsnvsnvdsnvk\n";

  

   if (error != RTCS_OK)

   {

      printf("\nRTCS failed to initialize, error = %X", error);

      _task_block();

   }

   _IP_forward = TRUE;

 

#ifdef BSP_ENET_DEVICE_COUNT

#if  (BSP_ENET_DEVICE_COUNT > 0)

   /*Following section is relevant only in case there as some enet driver available in BSP (FEC, MACNET, WIFI or other enet driver)*/

  

   ip_data.ip = ENET_IPADDR;

   ip_data.mask = ENET_IPMASK;

   ip_data.gateway = IPADDR(192,168,1,5);

  

   /* calcualte unique mac address from IP ADDRES */

   ENET_get_mac_address (ENET_DEVICE, ENET_IPADDR, enet_address);

   error = ipcfg_init_device (ENET_DEVICE, enet_address);

   if (error != RTCS_OK)

   {

      printf("\nFailed to initialize ethernet device, error = %X", error);

      _task_block();

   }

 

#if RTCSCFG_ENABLE_LWDNS

   LWDNS_server_ipaddr = ENET_GATEWAY;  

   ipcfg_add_dns_ip(ENET_DEVICE,LWDNS_server_ipaddr);

#endif /* RTCSCFG_ENABLE_LWDNS */

 

#if RTCS_DHCP

   printf("Contacting DHCP server ... ");

   error = ipcfg_bind_dhcp_wait(ENET_DEVICE, FALSE, &ip_data);

#else

   printf("Setting static IP address ... ");

   error = ipcfg_bind_staticip (ENET_DEVICE, &ip_data);

#endif /* RTCS_DHCP */

 

   if (error != IPCFG_ERROR_OK)

   {

      printf("\nRTCS failed to bind interface with IPv4, error = %X", error);

      _task_block();

   }

   else

   {

   printf("OK\n");  

   }

 

   ipcfg_get_ip(ENET_DEVICE, &ip_data);

   printf("\nIP Address      : %d.%d.%d.%d\n",IPBYTES(ip_data.ip));

   printf("\nSubnet Address  : %d.%d.%d.%d\n",IPBYTES(ip_data.mask));

   printf("\nGateway Address : %d.%d.%d.%d\n",IPBYTES(ip_data.gateway));

   printf("\nDNS Address     : %d.%d.%d.%d\n",IPBYTES(ipcfg_get_dns_ip(ENET_DEVICE,0)));

 

#endif /* BSP_ENET_DEVICE_COUNT > 0 */

#endif /* BSP_ENET_DEVICE_COUNT */  

 

  

   addr.sin_family = AF_INET;

   addr.sin_port = 60000;

   addr.sin_addr.s_addr = IPADDR(192,168,1,5);

  

   listensock = socket(AF_INET, SOCK_STREAM, 0);

   if (listensock == RTCS_SOCKET_ERROR) {

     printf("Failed \n");

     _task_block();

     }

  

   error = connect(listensock, (const sockaddr *)(&addr), sizeof(addr));

   if (error != RTCS_OK) {

    printf("connect failed\n", error);

    _task_block();

    }

 

   error = send(listensock,str,sizeof(str)-1,0);

   if(error != RTCS_OK)

   {

    printf("send failed\n", error);

    _task_block();

   }

Outcomes