我在用 C 语言进行客户端服务器编程时遇到问题。
问题是代码卡在客户端代码中的 while 循环中。代码是@客户端:
while ((n_read=((read(sockfd,&buffer,sizeof(buffer))))>0)
{
buffer[n_read]='\0';
write(fd,buffer,strlen(buffer));
printf("------- the value of n_read is : %d\n",n_read) ;
}
因此,当我在客户端使用 strace 调试此代码时,这里是系统调用的快照。我看到从服务器读取整个文件后n_read的值为1,但服务器在read=0后退出正常读取???我怎么解决这个问题
客户端代码的快照:
read(3, "._guardAgainstUnicode(pad)\n# Pad"..., 1025) = 1025
write(4, ".", 1) = 1
write(1, "------- the value of n_read is :"..., 35------- the value of n_read is : 1
) = 35
read(3, "crypted\nwith the already specifi"..., 1025) = 1025
write(4, "c", 1) = 1
write(1, "------- the value of n_read is :"..., 35------- the value of n_read is : 1
) = 35
read(3, " = bytes.fromhex('').join(result"..., 1025) = 1025
write(4, " ", 1) = 1
write(1, "------- the value of n_read is :"..., 35------- the value of n_read is : 1
) = 35