Other Parts Discussed in Thread: SYSBIOS, AM3358
Tool/software: TI-RTOS
Hi
I have creat a project to send data in UDP,this is my test file.
It can send 10 datas by udp,but it will failed after about a few minutes.
the log shows error on the API sendto,it returns -1,and I have check the error code,it is 64.
It will stop after sending 23,740 or so.
please help me to resolve this issue.
#define MAXBUF 10 #define NDK_UDPPORT 5555 /* talk to NDK echo server running on Concerto board */ #define SERVER_UDPPORT 5555 #define SERVER_IP "192.168.0.112" #define SLEEPTIME 1000 #define Sleep Task_sleep /* port the UDP echo Linux side tool "udpSendRecv" to NDK on Freon */ void udpEchoClient(void) { int i; SOCKET sockfd; int sleepTime = SLEEPTIME; struct sockaddr_in bindAddr; struct sockaddr_in servAddr; int bytes_read, bytes_sent; char *buffer; struct sockaddr_in fromAddr; /* originally was type 'sockaddr_storage' */ int fromAddrLen = sizeof(fromAddr); int ret = 0; int count = 0; int id; time_t start; unsigned int buffSize = MAXBUF; ret = fdOpenSession(TaskSelf()); UART_printf( "fdOpenSession result = %d\n",ret); Task_sleep(10000); buffer = malloc(buffSize); if (!buffer) { UART_printf("failed to malloc buffer!\n"); goto QUIT; } memset(buffer, 0, buffSize); /* initialize destination address */ memset(&servAddr, 0, sizeof(servAddr)); servAddr.sin_family = AF_INET; inet_aton(SERVER_IP, &servAddr.sin_addr); servAddr.sin_port = NDK_htons(SERVER_UDPPORT); /* create the socket */ /* TODO: assuming socket created successufully, due to cast error */ sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if(NULL == sockfd) { UART_printf( "socket failed\n"); } /* bind our socket to a particular port. Must bind else server reply drops! */ memset(&bindAddr, 0, sizeof(bindAddr)); bindAddr.sin_family = AF_INET; bindAddr.sin_addr.s_addr = INADDR_ANY; bindAddr.sin_port = NDK_htons(NDK_UDPPORT); if (bind(sockfd, (struct sockaddr *)&bindAddr, sizeof(bindAddr)) < 0) { UART_printf("failed to bind() the socket!\n"); goto QUIT; } /* print out sockets info */ UART_printf("Starting test with a %d uSec delay between transmits\n", sleepTime); /* loop */ i = 0; while (1) { buffer[0] = (char)(++i); buffer[buffSize - 1] = (char)~i; /* send the data */ bytes_sent = sendto(sockfd, buffer, buffSize, 0, (struct sockaddr *)&servAddr, sizeof(servAddr)); if (bytes_sent < 0 || bytes_sent != buffSize) { UART_printf("[id %d] stopping test. sendto returned %d (error %d)\n", id, bytes_sent, fdError()); goto QUIT; } Task_sleep(1000); } QUIT: UART_printf("--- at QUIT\n"); /* clean up */ if (sockfd) { fdClose(sockfd); } free(buffer); fdCloseSession(TaskSelf()); }