Altera_Forum
Honored Contributor
20 years agoUDP server NIOS II IDE
Hi all,
on the web I found an example of a UDP-server but it doens't seem to compile. It sais it doesn't know the right directory. Could you tell me what the problem is?! # include "lwip/sockets.h"# include <sys/types.h># include <netinet/in.h># include <stdio.h> int main(void) { int sockfd, addrlen; char buffer[100]; int no_of_bytes; struct sockaddr_in addr; struct sockaddr_in their_addr; //create a socket if ((sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) { printf("error:socket creation\n"); } printf(" Socket fd:%d \n", sockfd); addr.sin_port = htons(666); addr.sin_family = AF_INET; addr.sin_addr.s_addr = INADDR_ANY; memset(&(addr.sin_zero), 0, 8); //Bind the socket to the port printf("binding socket....\n"); if ( bind(sockfd, (struct sockaddr *) &addr, sizeof(addr)) < 0) { printf("error:Binding\n"); } printf("Socket bound\n"); addrlen = sizeof(struct sockaddr); if((no_of_bytes = recvfrom( sockfd, buffer, sizeof(buffer), 0, (struct sockaddr *) &their_addr, &addrlen)) == -1) { printf("error in receiving from %s \n", inet_ntoa(their_addr.sin_addr)); printf(" %d\n", no_of_bytes); exit(0); } else { printf("Received: %s\n", buffer); } upper_lower(buffer); sendto(sockfd, buffer, sizeof(buffer), 0, (struct sockaddr *) &their_addr, addrlen); close(sockfd); return 0; } It seems fine by me, and I changed some stuff, but the compiler doesn't recognize the folders. Cheers, Danny