[ Team LiB ] Previous Section Next Section

Chapter 1

1.3

Under Solaris, we get the following:

solaris % daytimetcpcli 127.0.0.1
socket error: Protocol not supported

To find more information on this error, we first use grep to search for the string Protocol not supported in the <sys/errno.h> header.

solaris % grep 'Protocol not supported' /usr/include/sys/errno.h
#define EPROTONOSUPPORT 120     /* Protocol not supported */

This is the errno returned by socket. We then look at the man page:

aix % man socket

Most man pages give additional, albeit terse, information toward the end under a heading of the form "Errors."

1.4

We change the first declaration to be the following:

int sockfd, n, counter = 0;

We add the statement

counter++;

as the first statement of the while loop. Finally, we execute

printf("counter = %d\n", counter);

before terminating. The value printed is always 1.

1.5

We declare an int named i and change the call to write to be the following:

for (i = 0; i < strlen(buff); i++)
    Write(connfd, &buff[i], 1);

The results vary, depending on the client host and server host. If the client and server are on the same host, the counter is normally 1, which means even though the server does 26 writes, the data is returned by a single read. But, one combination of client and server may produce two packets, and another combination 26 packets. (Our discussion of the Nagle algorithm in Section 7.9 explains one reason for this.)

The purpose of this example is to reiterate that different TCPs do different things with the data and our application must be prepared to read the data as a stream of bytes until the end of the data stream is encountered.


    [ Team LiB ] Previous Section Next Section