Skip to content

Instantly share code, notes, and snippets.

@adventureloop
Created January 26, 2014 10:45
Show Gist options
  • Select an option

  • Save adventureloop/8631062 to your computer and use it in GitHub Desktop.

Select an option

Save adventureloop/8631062 to your computer and use it in GitHub Desktop.
while(1) {
addr_len = sizeof(their_addr);
numbytes = recvfrom(sockfd,
buf,
MAXBUFLEN-1,
0,
(struct sockaddr *)&their_addr,
&addr_len);
if(numbytes == -1) {
//perror("recvfrom");
//exit(1);
continue;
}
printf("listener: got packet from %s ",
inet_ntop(their_addr.ss_family,
get_in_addr((struct sockaddr *)&their_addr),s,sizeof(s) ));
printf("%d bytes ",numbytes);
buf[numbytes] = '\0';
printf("containing \"%s\"\n",buf);
printf("Replying with: \"%s\"\n",buf);
numbytes = sendto(sockfd,
buf,
strlen(buf),
0,
(struct sockaddr *)&their_addr,
addr_len);
if(numbytes == -1) {
perror("replying: ");
}
usleep(166667);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment