MQX rtcs client TCP connect return 5705

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

MQX rtcs client TCP connect return 5705

跳至解决方案
3,229 次查看
jamatemaholu
Contributor I

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();

   }

标签 (1)
0 项奖励
回复
1 解答
2,247 次查看
danielchen
NXP TechSupport
NXP TechSupport

I have met this issue before, the cause is : I used twrk60d100 BSP libraries, and used the twrkn512 applications, the application does not match the BSP. But I am not sure if it works for your issue.

在原帖中查看解决方案

0 项奖励
回复
8 回复数
2,247 次查看
danielchen
NXP TechSupport
NXP TechSupport

Hi Jamate:

You are right, 5705= 0x1649, it means connection timeout. Please refer to rtcs.h

#define RTCSERR_TCP_TIMED_OUT       (RTCS_ERROR_BASE|0x649)  /* Connection timed out    */

Regarding your issue, you created a stream socket, you need to bind the socket to a specified addr first, you can read the document, MQXRTCSUG.pdf,  the chapter 3 (using sockets ) explained how to do it. And there is an example, section 3.30, for your reference


Have a great day,
Daniel

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复
2,247 次查看
jamatemaholu
Contributor I

Thank you very much for your response.

I have added bind to my code before connect function. But the result is same connection time out. I disabled firewall changed ethernet cable. Nothing helped.

In wireshark I can see messages like these... But does't seem familiar.

wireshark.bmp

I have verified that my port 11001 on PC is listenning.

netstat.bmp

When I try ping I receive:Reply from 192.168.1.5: Destination host is unrechable.  or time out...

Any other ideas? Some HW problem? My PC does not respond?

I really appreciate your time.

My modified code:

   addr.sin_family = AF_INET;

   addr.sin_port = 11001;

   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 = bind(listensock, &addr, sizeof(addr));

   if(error != RTCS_OK)

   {

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

     _task_block();

   }

  

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

    if (error != RTCS_OK) {

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

    _task_block();

    }

0 项奖励
回复
2,247 次查看
danielchen
NXP TechSupport
NXP TechSupport

Binding Sockets: it must bind the socket to a local port number. In your code , you bound to a remote PC. Connect is to a remote PC.

Here is a reference code

    sockaddr_in    addr;
    uint_32        sock;
    uint_32        error;
    uchar          cReadBuff[20]="Hello.\n";
    uint_32        value;

    printf("client started\n\r"); 
    sock = socket(PF_INET, SOCK_STREAM, 0);
    if (sock == RTCS_SOCKET_ERROR)
    {
        return;
    }

    value = 256;
    setsockopt(sock, SOL_TCP,OPT_TBSIZE,&value,sizeof(value));
    setsockopt(sock, SOL_TCP,OPT_RBSIZE,&value,sizeof(value));
  
    addr.sin_family      = AF_INET;
    addr.sin_port        = 0;
    addr.sin_addr.s_addr = INADDR_ANY;
  
    error = bind(sock, &addr, sizeof(addr));
    if (error != RTCS_OK)
    {
        return;
    }

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

    error = connect(sock, &addr, sizeof(addr));
    if (error != RTCS_OK)
    {
        shutdown(sock, FLAG_ABORT_CONNECTION);
        return;
    }

    printf("\nReady to send...\n");

   
        
   printf("Sending: %s", cReadBuff);
   
    //Sending message. 
    error = send(sock, (void *)cReadBuff, sizeof(cReadBuff), 0);
    if (error <= 0)
    {
        printf("There was an error trying to send to the server\n");
        return;
    }
   
    error = recv(sock, (void *)cReadBuff, sizeof(cReadBuff), 0);
    if (error <= 0)
    {
        printf("There was an error trying to send to the server\n");
        return;
    } 
   
    printf("Received: %s\n", cReadBuff);
    if (cReadBuff[0] != 'H')
    {
        shutdown(sock, FLAG_ABORT_CONNECTION);
    }
   

You can also check your hardware jumper setting, J6: position 2-3 [receive 50MHz from TWR-SER]


Have a great day,
Daniel

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

2,247 次查看
jamatemaholu
Contributor I

Thank you,

I forgot to set proper jumper setting. I have set jumper to proper jumper possitions.

TWR-K60N512 J6 2-3

TWR-SER J2 3-4

TWR-SER J3 2-3

TWR-SER J12 9-10

But I have stuck on other problem...

System did not start and  get stuck in this loop...

Did I miss something? I think my jumpers are in correct setting now.

MCG_C6 = (uint8_t)0x18U;

  while((MCG_S & MCG_S_IREFST_MASK) != 0x00U) { /* Check that the source of the FLL reference clock is the external reference clock. */

  }

Thank you, very much for your help.

0 项奖励
回复
2,248 次查看
danielchen
NXP TechSupport
NXP TechSupport

I have met this issue before, the cause is : I used twrk60d100 BSP libraries, and used the twrkn512 applications, the application does not match the BSP. But I am not sure if it works for your issue.

0 项奖励
回复
2,247 次查看
jamatemaholu
Contributor I

Looks like it is working now. I had bug in my C# prog. But still I can see IPA protocol in the wireshark? Why IPA?

Thank you.

0 项奖励
回复
2,247 次查看
gorakk
Contributor IV

Wireshark identifies the TCP port numbers 3002, 3003, 3006, 4249, 4250, and 5000  and the UDP port number 3006 as being GSM over IP.

To prevent Wireshark from tagging the packet as IPA, go into Preferences, find the GSM over IP entry in Protocols and clear the port fields.

0 项奖励
回复
2,247 次查看
jamatemaholu
Contributor I

Thank you,

What I did...

completely uninstall a Codewarriror and MQX...

Install new version of the Codewarrior and MQX, rebuild the MQX and now I am able to perform send function. I had wrong settings of the jumpers and something was wrong with MQX...

Now the program can perform send function, but still it is not possible pair with my C# program.

I can see these messages (wireshark):

ipaprotocol.bmp

I am able to see content what I sent in the 4 line (No. 46). This line is marked that use IPA protocol ( "GSM over IP" protocol). Which does not make  sense for me.

This message is from the Tower Kit, but why IPA?

Second line contain:

Header CheckSum: Header checksum: 0x0000 [incorrect, should be 0x5a45 (may be caused by "IP checksum offload"?)]

Thank you very much for you time and help.

0 项奖励
回复