Java NIO read()End Of Stream [英] Java NIO read() End Of Stream

查看:165
本文介绍了Java NIO read()End Of Stream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Java NIO来接受,读取和写入我的服务器。

I'm using Java NIO in to accept, read and write in my server.

文档它说 SocketChannel.read()函数将返回从套接字读取的字节数,如果它到达流的末尾则返回-1。

In the documentation it said that the SocketChannel.read() function will return the number of bytes read from socket, and -1 if it reach end of stream.

现在 - 我真的不明白End Of Stream是什么意思?是否与 borken pipe 错误相同?

Now - i don't really understand what does "End Of Stream" mean? is it as same as borken pipe error ?

这是否意味着双方和我的连接都丢失了应该关闭SocketChannel?

Does it mean that the connection is lost for both side and i should close the SocketChannel ?

如果有人可以解释更多关于它的话,我会非常满意 - 并举一些根据它来正确使用和行为的例子。

I would be really great full if someone can explain more about it - and give some example of using and behaving correctly according to it..

推荐答案

End Of Stream意味着没有更多内容可供阅读,因为另一端已经关闭了流。

End Of Stream means there is nothing more to read because the other end has closed the stream.

0 不是什么,它是零。

你将如果连接意外丢失,则会收到异常。即另一端没有优雅地关闭连接。

You will get an exception if the connection is lost unexpectedly. I.e. the other end had not closed the connection gracefully.

这篇关于Java NIO read()End Of Stream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆