My little UDP Server:
under windows: no error and it runs very well.Code:#include<stdio.h> #include<signal.h> #include<sys/time.h> #include<sys/socket.h> #include<sys/types.h> #include<netinet/in.h> #include<netdb.h> #define PORTS 6260 //port server main() { struct sockaddr_in sin_serv; // server structure struct sockaddr_in sin_clien; // client structure int namelen, sock; int pid, statut,n,i,lg; char line[100]; if(sock_serv=sock(AF_INET, SOCK_DGRAM, IPPROTO_UDP)<0) { perror("socket" ); exit(1); } bzero(&sin_serv,sizeof(sin)); sin_serv.sin_family=AF_INET; sin_serv.sin_port=htons(PORTS); sin_serv.sin_addr.s_addr=INADDR_ANY; if(bind(sin_serv,&sin_serv,sizeof(sin_serv))<0) { perror("bind" ); exit(2); } /************ Receive the message **************/ n=recvfrom(sock_serv,line,strlen(line),0,&sin_clien,sizeof(sin_clien)); printf("my message %s is well received it is longer: %d", line,strlen(line)); return; }
Linux (Ubuntu): no error but when I run it I see an error: bind: Socket operation on non-socket! why this error? and mean what?


Reply With Quote

Bookmarks