Here is my code to send/receive data on UDP on a MQX task
uint32_t error = RTCS_create();
if (error != RTCS_OK)
{
printf("\nRTCS failed to initialize, error = %X", error);
_task_block();
}
ip_data.ip = ENET_IPADDR;
ip_data.mask = ENET_IPMASK;
ip_data.gateway = ENET_GATEWAY;
/* 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();
}
error = ipcfg_bind_staticip (ENET_DEVICE, &ip_data);
sock_udp = socket(PF_INET, SOCK_DGRAM, 0);
local_addr.sin_family = AF_INET;
local_addr.sin_port = DEF_HARTIP_PORT;
local_addr.sin_addr.s_addr = INADDR_ANY;
bind(sock_udp, (sockaddr *)(&local_addr), sizeof(sockaddr_in));
while (1)
{
len_request = recvfrom(sock_udp, &msg_buffer[0], sizeof(hartmsg_buffer), 0, (struct sockaddr *) &local_addr,&remote_len);
...Process the received data * compose response
sendto(sock_udp, &hartmsg_buffer[0], tx_size, 0, (struct sockaddr *)&local_addr,sizeof(sockaddr_in));
}
When i hook up the UDP client, the communication works fine for few iterations. The recvfrom() dont process all the requests and 1 out 10 request dont generate response.
Am i missing something like a time delay or something?