Hi,
IT-RTOS - 2.10.01.38
NDK 2.24.01.18
TM4C129ENCPDT
I have the interface to work properly with UDP server (eg UDP ECHO).
When I put it to work as a UDP client displays the following error message in the sendto function:
EHOSTUNREACH (65)
It seems he does not find a UDP server on the network, but the server is present on the network. code for the client is as follows:
void UDPSocket_Client(UArg a0, UArg a1) { SOCKET client; struct sockaddr_in servAddr; int bytes_read; int bytessent; struct sockaddr_in fromAddr; int fromAddrLen = sizeof(fromAddr); unsigned int buffSize = MAXBUF; char buffer[MAXBUF]; int fdOpenResult = 0; System_printf("UDP CLIENT.\n"); System_flush(); fdOpenResult = fdOpenSession(TaskSelf()); while (fdOpenResult == 0) { System_printf("fdOpenSession failed\n"); System_flush(); fdCloseSession(TaskSelf()); Task_sleep(5); fdOpenResult = fdOpenSession(TaskSelf()); } /* initialize destination address IP server */ memset(&servAddr, 0, sizeof(servAddr)); servAddr.sin_family = AF_INET; //servAddr.sin_addr.s_addr = inet_addr("192.168.1.82"); inet_aton("192.168.1.82", &servAddr.sin_addr); servAddr.sin_port = htons(59974); client = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (client < 0) { // error System_printf("ERROR SOCKET: (%d)\n", fdError()); System_flush(); goto QUIT; } while (1) { GPIO_write(Board_LED0, Board_LED_OFF); GPIO_write(Board_LED1, Board_LED_ON); Task_sleep(50); GPIO_write(Board_LED1, Board_LED_OFF); bytessent = sendto(client, buffer, buffSize, 0,(struct sockaddr *) &servAddr, sizeof(servAddr)); if (bytessent < 0) { // System_printf("ERROR SENDTO: (%d)\n", fdError()); System_flush(); GPIO_write(Board_LED1, Board_LED_ON); goto QUIT; } bytes_read = recvfrom(client, buffer, buffSize, MSG_DONTWAIT, (struct sockaddr *) &fromAddr, &fromAddrLen); if (bytes_read < 0) { // || bytes_read != buffSize System_printf("ERROR RECVFROM: (%d)\n", fdError()); System_flush(); goto QUIT; } else { System_printf("Received %d bytes\n", bytes_read); System_flush(); } GPIO_write(Board_LED0, Board_LED_ON); } QUIT: if (client) { GPIO_write(Board_LED0, Board_LED_OFF); fdClose(client); Reset_Main(); } fdCloseSession(TaskSelf()); }
Because it can not find the server on the network?
Regards
Aquino