0

I've recently become interested in trying to adapt my Rock-Paper-Scissors game into a multiplayer-friendly program, so today I decided I'd look up a tutorial on servers. It seems I'm following it precisely (aside from using a different IDE). However, something is going wrong and I'm not sure exactly what it is, and it works fine for the tutorial maker. I've looked up EOFException but it didn't exactly help me out.

The tutorial on Youtube

My screenshot of the issue. screenshot

[Documentation on EOFException](I had a link here, but I need at least 10 reputation to post more than two links)

"Signals that an end of file or end of stream has been reached unexpectedly during input. This exception is mainly used by data input streams to signal end of stream. Note that many other input operations return a special value on end of stream rather than throwing an exception."

[A similar but apparently unresolved question asked here](I had a link here too]

By the way, if you look up exactly what I've posted here, you'll also find that I've asked it at DaniWeb. I'm just posting in multiple places in case it isn't resolved at one or the other. If it is, well... the more knowledge, the better.

dav1dsm1th
  • 1,687
  • 2
  • 20
  • 24
ShowALK
  • 1
  • 2

1 Answers1

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?

user207421
  • 305,947
  • 44
  • 307
  • 483
  • Thanks for your input. I'll be sure to close the sockets. I've gone through the tutorial a second time to check things out. The code is exactly the same as he has it in the video, and he runs it just fine near the end. Maybe it's a problem with my ports. – ShowALK Mar 20 '14 at 01:38
  • By the way, what you see here is all the code provided in the first tutorial, which, again, executed perfectly for the tutorial maker in his video. – ShowALK Mar 20 '14 at 01:49