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. |