通过网络进行对象反序列化

发布于 2024-08-06 14:22:03 字数 641 浏览 2 评论 0原文

当我尝试通过网络从 ObjectInputStream 读取对象时,我收到一个异常:

Socket socket = new Socket("localhost", 4444);
ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
while ((Object o = ois.readObject()) != null) {
}

这是我得到的异常:

java.io.EOFException
    at java.io.ObjectInputStream$BlockDataInputStream.peekByte(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.readObject(Unknown Source)

连接本身似乎很好,因为我能够通过网络读取字符串,但对象不起作用。

由于它是 EOFExcepetion,我假设流当前不再发送数据。 (发送第一个对象后就可以了)。 所以我在想也许我使用对象反序列化的方式是错误的?

这里可能有什么问题?谢谢!

i am getting an excepetion when i try to read an object from an ObjectInputStream via network like this:

Socket socket = new Socket("localhost", 4444);
ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
while ((Object o = ois.readObject()) != null) {
}

Here is the exception I get:

java.io.EOFException
    at java.io.ObjectInputStream$BlockDataInputStream.peekByte(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.readObject(Unknown Source)

The connection itself seems fine, since i am able to read strings via the network, but objects dont work.

Since it is an EOFExcepetion i assume that the stream currently sends no more data. (which is ok after the first object being sent).
so i was thinking maybe i am using objectdeserialization the wrong way?

what could be the problem here? thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橙味迷妹 2024-08-13 14:22:03

为什么不调用 available () 检查是否有东西可读?发布您的服务器端代码可能是值得的。目前我们只看到了故事的一方面。

Why not call available() to check whether there's stuff to read ? It's probably worth publishing your server side code. At the moment we're seeing only one side of the story.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文