更新时间:2022-04-20 23:10:04
read()
函数到达文件末尾时将返回0.
The read()
function will return 0 when it reaches the end of file.
因此,在您的情况下,有一个循环迭代接收了"Hello world"
,然后又有一个迭代,除了read()
返回0外,将不接收任何内容.因此,"Client:"显示为空字符串.
So in your case, there is a first loop iteration that receives "Hello world"
, then there's one more iteration, that will receive nothing but read()
returns 0. So "Client :" is displayed with an empty string.
此外,请注意:
read()
将对应于客户端端的一个println()
.因此,对于较长的邮件,您将冒着分批接收的风险.然后,在输出中,您会在消息文本中看到几个客户端". read()
on the server side will correspond to one println()
on the client side. So for longer messages, you'll risk to receive it in pieces. On the output you'd then see several "Client" within the message text.