通过网络进行对象反序列化
当我尝试通过网络从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不调用 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.