0

我最近对尝试将我的 Rock-Paper-Scissors 游戏改编成一个多人友好的程序感兴趣,所以今天我决定查找有关服务器的教程。看来我正在精确地遵循它(除了使用不同的 IDE)。但是,出了点问题,我不确定它到底是什么,它对教程制作者来说很好用。我查过 EOFException 但它并没有完全帮助我。

Youtube 上的教程

我的问题截图。 截屏

[EOFException 上的文档](我在这里有一个链接,但我需要至少 10 个声望才能发布两个以上的链接)

“表示在输入过程中意外到达文件结尾或流结尾。此异常主要由数据输入流用来表示流结束。请注意,许多其他输入操作在流结束时返回一个特殊值而不是抛出一个例外。”

[这里提出了一个类似但显然未解决的问题](我在这里也有一个链接]

顺便说一句,如果您确切地查看我在此处发布的内容,您还会发现我在 DaniWeb 上问过它。我只是在多个地方发帖,以防其中一个没有解决。如果是,那么……知识越多越好。

4

1 回答 1

0

EOFException during readUTF() just means it's reached the end of the stream, like it says on the tin. Note that this method doesn't return null at end of stream, unlike readLine() (but like all other readXXX() methods).

It can also mean that your sending and receiving is out of sync, e.g. you are trying to read some ridiculously large number of bytes because you left out a readInt() or similar, or you wrote something extra at the peer that you shouldn't have, so you're trying to read the next bytes in the stream as the result of writeUTF() when it isn't. This is an application protocol error.

How this happened in the code you posted is another question, but your code doesn't close the sockets, which doesn't help. Add an out.close() to your server code, and in.close() to the client code. However I cannot reproduce your problem with or without these closes. Are you sure this is the real code?

于 2014-03-19T23:07:38.223 回答