HP Rp7410 BSD Sockets Interface Programmer's Guide - Page 56
CAUTION: If you increase the number of requests
View all HP Rp7410 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 56 highlights
Using Internet Stream Sockets Example Using Internet Stream Sockets * addrlen needs to be passed in as a pointer, * because getsockname returns the actual length * of the address. */ addrlen = sizeof(struct sockaddr_in); if (getsockname(s, &myaddr_in, &addrlen) == -1) { perror(argv[0]); fprintf(stderr, "%s: unable to read socket address\n", argv[0]); exit(1); } /* Print out a startup message for the user. */ time(&timevar); /* The port number must be converted first to * host byte order before printing. On most hosts, * this is not necessary, but the ntohs() call is * included here so this program could easily be * ported to a host that does require it. */ printf("Connected to %s on port %u at %s", argv[1], ntohs(myaddr_in.sin_port), ctime(&timevar)); /* This sleep simulates any preliminary processing * that a real client might do here. */ sleep(5); /* Send out all the requests to the remote server. * In this case five are sent but any random number * could be used. The first four bytes of buf are * set up to contain the request number. This * number will be returned in the server's reply. */ /* CAUTION: If you increase the number of requests * sent or the size of the requests, you should be * aware that you could encounter a deadlock * situation. Both the client's and server's * sockets can only queue a limited amount of * data on their receive queues. */ for (i=1; i