/*CLICLIENT CLIENT CONNESSION LESS SU INTERNET */ /*parametri: hostname port */ #include #include #include #include #include #define BUFSZ 256 #define DATA "012345678901234567890123456789..." main(argc, argv) int argc; char *argv[]; { int sock,flength; struct sockaddr_in name; int bufin[BUFSZ],bufout[BUFSZ]; int i; struct hostent *hp, *gethostbyname(); if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { perror("server:socket"); exit(1); } hp = gethostbyname(argv[1]); if (hp == 0) { fprintf(stderr, "%s: host sconosciuto", argv[1]); exit(2); } bcopy((char *)hp->h_addr,(char *)&name.sin_addr,hp->h_length); name.sin_family = AF_INET; name.sin_port = htons(atoi(argv[2])); i=0; while (1) { i++; bufout[0] = getpid(); /* pid */ bufout[1] = i; /* # messaggio */ if (sendto(sock,bufout, sizeof bufout,0, (struct sockaddr*)&name,sizeof name) < 0) perror("sending datagram packet"); if (recvfrom(sock,bufin, sizeof(bufin),0, 0, 0) < 0) perror("receiving datagram packet"); printf("\r -->%d<--%d<--%d", bufin[0], bufin[1],bufin[2]); } close(sock); exit(0); }