1.3 把daytimetcpcil.c中socket的参数改为9999,编译并运行,结果:
ethan@ethan-virtual-machine:~/unp/unpv13e/intro$ ./daytimetcpcli 127.0.0.1
socket error: Address family not supported by protocol
使用
man errno
查找,发现errno对应的是
EAFNOSUPPORT Address family not supported (POSIX.1)
1.4 给cli加一个计数器,返回read大于零的次数。
int cnt = 0;
while ( (n = read(sockfd, recvline, MAXLINE)) > 0) {
++cnt;
recvline[n] = 0; /* null terminate */
if (fputs(recvline, stdout) == EOF)
err_sys("fputs error");
}
if (n < 0)
err_sys("read error");
printf("%d\n", cnt);
运行结果:
ethan@ethan-virtual-machine:~/unp/unpv13e/intro$ ./daytimetcpcli 127.0.0.1
Fri Dec 7 20:00:41 2018
1
1.6 把两个程序的端口号都改为9999,然后把write改为循环调用,但是运行的结果还是每次cnt=1
。
snprintf(buff, sizeof(buff), "%.24s\r\n", ctime(&ticks));
for(int i=0; i < strlen(buff); ++i){
Write(connfd, &buff[i], 1);
}
运行结果:
ethan@ethan-virtual-machine:~/unp/unpv13e/intro$ ./daytimetcpcli 127.0.0.1
Fri Dec 7 20:38:35 2018
1
看了下课后的解释