Created
June 5, 2015 16:17
-
-
Save sl0ki/8c188979a2390b1acea0 to your computer and use it in GitHub Desktop.
fs_serv_evt.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Sample UDP server */ | |
#include <sys/socket.h> | |
#include <netinet/in.h> | |
#include <stdio.h> | |
int main(int argc, char**argv) | |
{ | |
int sockfd,n; | |
struct sockaddr_in servaddr,cliaddr; | |
socklen_t len; | |
char mesg[1000]; | |
sockfd=socket(AF_INET,SOCK_DGRAM,0); | |
bzero(&servaddr,sizeof(servaddr)); | |
servaddr.sin_family = AF_INET; | |
servaddr.sin_addr.s_addr=htonl(INADDR_ANY); | |
servaddr.sin_port=htons(32000); | |
bind(sockfd,(struct sockaddr *)&servaddr,sizeof(servaddr)); | |
for (;;) | |
{ | |
len = sizeof(cliaddr); | |
n = recvfrom(sockfd,mesg,1000,0,(struct sockaddr *)&cliaddr,&len); | |
sendto(sockfd,mesg,n,0,(struct sockaddr *)&cliaddr,sizeof(cliaddr)); | |
printf("-------------------------------------------------------\n"); | |
mesg[n] = 0; | |
printf("Received the following:\n"); | |
printf("%s",mesg); | |
printf("-------------------------------------------------------\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment