Altera_Forum
Honored Contributor
14 years agoEthernet link on DE2-115
Hi,
I am using DE2-115 to do Ethernet UDP data transferring with the simple_socket_server template. Everything seems correct but the link will fail for several seconds at the beginning every time I run the code (the return value of sendto is -1). The data rate is about 4Mbps. Please give me some idea if there is some bug in the following code. void SSSSimpleSocketServerTask() { int tx_buffer_size = SSS_TX_BUF_SIZE; int udp_socket; int l=0; char data[100]={0}; struct sockaddr_in cliaddr; struct sockaddr_in seraddr; if((udp_socket = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP))<0) printf("Error of socket creating"); cliaddr.sin_family = AF_INET; cliaddr.sin_port = htons(UDP_PORT); cliaddr.sin_addr.s_addr = INADDR_ANY; seraddr.sin_family = AF_INET; seraddr.sin_port = htons(UDP_PORT); seraddr.sin_addr.s_addr = inet_addr("192.168.1.12"); setsockopt(udp_socket, SOL_SOCKET, SO_SNDBUF, (const char*)&tx_buffer_size, sizeof(tx_buffer_size)); if ((bind(udp_socket, (struct sockaddr *)&cliaddr, sizeof(cliaddr))) < 0) alt_NetworkErrorHandler(EXPANDED_DIAGNOSIS_CODE,"[sss_task] Bind failed"); printf("[sss_task] Simple Socket Server listening on port %d\n", UDP_PORT); while(1) { // printf("t\n"); /***** Problem here, l will be -1 for the first several seconds *****/ l = sendto(udp_socket, data, 100, 0, (struct sockaddr *)&seraddr, sizeof(seraddr)); if(l<0) printf("%d",l); // usleep(100); } }