/*COICLIENT - CLIENT CONNESSION ORIENTED SU INTERNET*/ #include #include #include #include #include #define NSTRS 3 #define MSGLEN 32 main(argc, argv) int argc; char *argv[]; { register int i, s; int fromlen, pid; struct hostent *hp; struct sockaddr_in name; char str1[200]; if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) { perror("client: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])); if (connect(s, &name, sizeof name) < 0) { perror("client: connect"); exit(1); } for (i=0; i < NSTRS; i++) { fromlen = recv(s, str1,MSGLEN,0); str1[fromlen] = '\0'; printf("%d: %s dim:%d\n",i,str1, fromlen); } for (i=0; i< NSTRS; i++) send(s,argv[3], MSGLEN, 0); close(s); exit(0); }