/*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, ns,nl; int fromlen, pid; struct hostent *hp; struct sockaddr_in name, name1; char str1[1024]; if ((ns = socket(AF_INET, SOCK_STREAM, 0)) < 0) { perror("client:socket"); exit(1); } if ((nl = 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])); bcopy((char *)hp->h_addr,(char *)&name1.sin_addr,hp->h_length); name1.sin_family = AF_INET; name1.sin_port = htons(atoi(argv[2])*2); if (connect(ns, &name, sizeof name) < 0) { perror("client: connect1"); exit(1); } if (connect(nl, &name1, sizeof name1) < 0) { perror("client: connect2"); exit(1); } i=0; while(1) { printf("write eseguita %d\n", write(ns,argv[3], MSGLEN)); fromlen = read(nl, str1,MSGLEN); str1[fromlen] = '\0'; printf("%d: %s dim:%d\n",i,str1, fromlen); i++; } close(ns); exit(0); }