Mercurial > hg > beaglert
annotate resources/network/udp-client-sweep.c @ 270:de37582ce6f3 prerelease
Added OSCServer and OSCClient
author | Liam Donovan <l.b.donovan@qmul.ac.uk> |
---|---|
date | Tue, 17 May 2016 15:56:18 +0100 |
parents | adcb57fd3d75 |
children |
rev | line source |
---|---|
giuliomoro@28 | 1 /* UDP client in the internet domain */ |
giuliomoro@28 | 2 #include <sys/types.h> |
giuliomoro@28 | 3 #include <sys/socket.h> |
giuliomoro@28 | 4 #include <netinet/in.h> |
giuliomoro@28 | 5 #include <arpa/inet.h> |
giuliomoro@28 | 6 #include <netdb.h> |
giuliomoro@28 | 7 #include <stdio.h> |
giuliomoro@28 | 8 #include <stdlib.h> |
giuliomoro@28 | 9 #include <unistd.h> |
giuliomoro@28 | 10 #include <string.h> |
giuliomoro@28 | 11 |
giuliomoro@28 | 12 void error(const char *); |
giuliomoro@28 | 13 int main(int argc, char *argv[]) |
giuliomoro@28 | 14 { |
giuliomoro@28 | 15 int sock, n; |
giuliomoro@28 | 16 unsigned int length; |
giuliomoro@28 | 17 struct sockaddr_in server, from; |
giuliomoro@28 | 18 struct hostent *hp; |
giuliomoro@28 | 19 char buffer[256]; |
giuliomoro@28 | 20 |
giuliomoro@28 | 21 if (argc != 3) { printf("Usage: server port\n"); |
giuliomoro@28 | 22 exit(1); |
giuliomoro@28 | 23 } |
giuliomoro@28 | 24 |
giuliomoro@28 | 25 server.sin_family = AF_INET; |
giuliomoro@28 | 26 hp = gethostbyname(argv[1]); |
giuliomoro@28 | 27 if (hp==0) error("Unknown host"); |
giuliomoro@28 | 28 |
giuliomoro@28 | 29 bcopy((char *)hp->h_addr, |
giuliomoro@28 | 30 (char *)&server.sin_addr, |
giuliomoro@28 | 31 hp->h_length); |
giuliomoro@28 | 32 server.sin_port = htons(atoi(argv[2])); |
giuliomoro@28 | 33 length=sizeof(struct sockaddr_in); |
giuliomoro@28 | 34 while (1){ |
giuliomoro@28 | 35 sock= socket(AF_INET, SOCK_DGRAM, 0); |
giuliomoro@28 | 36 if (sock < 0) error("socket"); |
giuliomoro@28 | 37 bzero(buffer,256); |
giuliomoro@28 | 38 // printf("Please enter the message: "); |
giuliomoro@28 | 39 // fgets(buffer,255,stdin); |
giuliomoro@28 | 40 double freq=50; |
giuliomoro@28 | 41 while(1){ |
giuliomoro@28 | 42 freq*=1.001; |
giuliomoro@28 | 43 if(freq>20000) freq=50; |
giuliomoro@28 | 44 sprintf(buffer,"%.4f;",freq); |
giuliomoro@28 | 45 n=sendto(sock,buffer, |
giuliomoro@28 | 46 strlen(buffer),0,(const struct sockaddr *)&server,length); |
giuliomoro@28 | 47 if (n < 0) error("Sendto"); |
giuliomoro@28 | 48 usleep(1000); |
giuliomoro@28 | 49 } |
giuliomoro@28 | 50 } |
giuliomoro@28 | 51 close(sock); |
giuliomoro@28 | 52 return 0; |
giuliomoro@28 | 53 } |
giuliomoro@28 | 54 |
giuliomoro@28 | 55 void error(const char *msg) |
giuliomoro@28 | 56 { |
giuliomoro@28 | 57 perror(msg); |
giuliomoro@28 | 58 exit(0); |
giuliomoro@28 | 59 } |