AnsweredAssumed Answered

Simple UDP communication

Question asked by sergemonnerat on Nov 9, 2012
Latest reply on Jan 30, 2013 by Garabo


I try to setup a simple udp communication between an UDP client on my PC and the K60 tower. I have wireshark on the PC and I see the outgoing frame to the K60. I have follow the socket example Quote of the Day in the Freescale MQX™ RTCS™ User’s Guide.

When I run the app on the board the RTCS_selectall function return immediately (before I send anything through the network) with a valid socket number but when I read the datas with the recvfrom function the IP address, the TCP port and the datas are 0. Afterthat when I try to send UDP frame's the selectall function never detect activity on the socket. Thank for your help. The udp task that I write:





* Function Name  : udp_task

* Returned Value : void

* Comments       :



void udp_task(uint_32 temp)


  static uint_32      sSocketHndl;

  static uint_32      sListenSocketHndl;

  static uint_16      sRemoteRxLengh;

  static int_32        sNbOfByteReceived;

  static int_32        sNbOfByteTransmit;

  static sockaddr_in      sLocalAddr;

  static sockaddr_in      sRemoteTxAddr;

  static sockaddr_in      sRemoteRxAddr;

  static uchar                sUdpRemoteBuffer[kUDP_BUF_LEN];         

  static int_32       error;

  static uint_32     sUerror;

  static _enet_handle           sEthernetHandle;

  static _rtcs_if_handle        sRTCSHandle;

  static _enet_address          sMacAddress;


  /* We are running on a memory constrained device, lower RTCS's defaults */

  /* runtime RTCS configuration */

  _RTCSPCB_init = 4;

  _RTCSPCB_grow = 2;

  _RTCSPCB_max = 6;

  _RTCS_msgpool_init = 4;

  _RTCS_msgpool_grow = 2;

  _RTCS_msgpool_max  = 8;

  _RTCS_socket_part_init = 4;

  _RTCS_socket_part_grow = 2;

  _RTCS_socket_part_max  = 6;

  _RTCSTASK_stacksize = 2200;


  error = RTCS_create();


  ENET_get_mac_address(DEMOCFG_DEFAULT_DEVICE, ENET_IPADDR, sMacAddress);

  sUerror = ENET_initialize(DEMOCFG_DEFAULT_DEVICE,sMacAddress, 0, &sEthernetHandle);



  sUerror = RTCS_if_add(sEthernetHandle, RTCS_IF_ENET, &sRTCSHandle);



  sUerror = RTCS_if_bind(sRTCSHandle, ENET_IPADDR, ENET_IPMASK);



  // Config du gateway address





  sSocketHndl = socket(PF_INET, SOCK_DGRAM, 0);

  if(sSocketHndl == RTCS_SOCKET_ERROR)



  sLocalAddr.sin_family = AF_INET;

  sLocalAddr.sin_port = 10;

  sLocalAddr.sin_addr.s_addr = IPADDR(157,26,100,93);//INADDR_ANY;


  sUerror = bind(sSocketHndl, &sLocalAddr, sizeof(sLocalAddr));

  if(sUerror != RTCS_OK)





  sRemoteTxAddr.sin_family = AF_INET;

  sRemoteTxAddr.sin_port = 8;

  sRemoteTxAddr.sin_addr.s_addr = IPADDR(157,26,100,78);


  sUerror=connect(sListenSocketHndl, &sRemoteTxAddr, sizeof(sRemoteTxAddr));

  if(sUerror != RTCS_OK)







  sSocketHndl = RTCS_selectall(0);

  if(sSocketHndl == RTCS_SOCKET_ERROR)





  memset(&sRemoteRxAddr, 0, sizeof(sRemoteRxAddr));

  memset(&sUdpRemoteBuffer,0, kUDP_BUF_LEN); //clean out buffer

  sRemoteRxLengh = sizeof(sRemoteRxAddr);

  sNbOfByteReceived = recvfrom(sSocketHndl, sUdpRemoteBuffer, kUDP_BUF_LEN, 0, &sRemoteRxAddr, &sRemoteRxLengh);

  if (sNbOfByteReceived == RTCS_ERROR)



  sRemoteRxLengh = sizeof(sRemoteRxLengh);

  sNbOfByteTransmit = sendto(sSocketHndl,"Fuck hackers",13,RTCS_MSG_NOLOOP,&sRemoteRxAddr, sRemoteRxLengh);

  if (sNbOfByteTransmit == RTCS_ERROR)