Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

UDP server NIOS II IDE

Altera_Forum
Honored Contributor II
1,481 Views

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&#39;t recognize the folders. 

 

Cheers, 

 

Danny
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
461 Views

So, what excuse is the compiler giving you?

0 Kudos
Altera_Forum
Honored Contributor II
461 Views

 

--- Quote Start ---  

originally posted by mike desimone@Nov 1 2005, 03:14 PM 

so, what excuse is the compiler giving you? 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=10726) 

--- quote end ---  

 

--- Quote End ---  

 

 

It&#39;s saying that it doesn&#39;t recognize the file "in.h", but I don&#39;t know how to make a path to that file. I am using a blank project, cause I don&#39;t need all of the other examples. I just a few simpel things to establish a connection. But this seems to be written in Visual C. Could I use this with the MicroC/OS-II?! 

 

cheers, 

 

Danny
0 Kudos
Altera_Forum
Honored Contributor II
461 Views

Danny, 

 

For the necessary includes, and other stuff you have to take care of, please view either the simple socket server example or the web server example. These are both good places to start, even though they&#39;re both based upon TCP. You need to understand one (or both) of these examples prior to proceeding! 

 

The only difference, in your case, is the tasks you&#39;ll be kicking off with sys_thread_new(). You could simply add a new task calling a function which wraps your code. 

 

Best Regards, 

 

- slacker
0 Kudos
Reply