giuliomoro@28: /* UDP client in the internet domain */ giuliomoro@28: #include giuliomoro@28: #include giuliomoro@28: #include giuliomoro@28: #include giuliomoro@28: #include giuliomoro@28: #include giuliomoro@28: #include giuliomoro@28: #include giuliomoro@28: #include giuliomoro@28: giuliomoro@28: void error(const char *); giuliomoro@28: int main(int argc, char *argv[]) giuliomoro@28: { giuliomoro@28: int sock, n; giuliomoro@28: unsigned int length; giuliomoro@28: struct sockaddr_in server, from; giuliomoro@28: struct hostent *hp; giuliomoro@28: char buffer[256]; giuliomoro@28: giuliomoro@28: if (argc != 3) { printf("Usage: server port\n"); giuliomoro@28: exit(1); giuliomoro@28: } giuliomoro@28: giuliomoro@28: server.sin_family = AF_INET; giuliomoro@28: hp = gethostbyname(argv[1]); giuliomoro@28: if (hp==0) error("Unknown host"); giuliomoro@28: giuliomoro@28: bcopy((char *)hp->h_addr, giuliomoro@28: (char *)&server.sin_addr, giuliomoro@28: hp->h_length); giuliomoro@28: server.sin_port = htons(atoi(argv[2])); giuliomoro@28: length=sizeof(struct sockaddr_in); giuliomoro@28: while (1){ giuliomoro@28: sock= socket(AF_INET, SOCK_DGRAM, 0); giuliomoro@28: if (sock < 0) error("socket"); giuliomoro@28: bzero(buffer,256); giuliomoro@28: // printf("Please enter the message: "); giuliomoro@28: // fgets(buffer,255,stdin); giuliomoro@28: double freq=50; giuliomoro@28: while(1){ giuliomoro@28: freq*=1.001; giuliomoro@28: if(freq>20000) freq=50; giuliomoro@28: sprintf(buffer,"%.4f;",freq); giuliomoro@28: n=sendto(sock,buffer, giuliomoro@28: strlen(buffer),0,(const struct sockaddr *)&server,length); giuliomoro@28: if (n < 0) error("Sendto"); giuliomoro@28: usleep(1000); giuliomoro@28: } giuliomoro@28: } giuliomoro@28: close(sock); giuliomoro@28: return 0; giuliomoro@28: } giuliomoro@28: giuliomoro@28: void error(const char *msg) giuliomoro@28: { giuliomoro@28: perror(msg); giuliomoro@28: exit(0); giuliomoro@28: }