I have a question that needs assistance.
I have written
1) a Java swing program that send a string using DataInputStream.readUTF() and also a few integer using DataInputStream.readInt() continuously using Threads.
2) The Java swing program will send to another Java program that will process those string and integer through a socket by continuing to listen to port 12345 and ip address 127.0.0.1 in an never-ending thread.
It was alright at the start but as the program goes, I got a EOFException caught by the program that acts as a server for one of the integer sent by the Java swing program.
May I know what could have caused this problem? I am new to Threads and I/O. One more thing, I am quite confused with my concept in I/O. For example, in my case, how do Java send string and integer to the other program. Do the program send them all together or do they send those data one by one? If they send them one by one, how to make the Java program send them altogether because I need them so that the other program can process and exception (for example, EOFException)will be thrown if one of the data is missing.
My code is a bit confusing and quite a lot. Hope you don't mind. The program is actually my school assignment. It is actually used to play the addition game. It is used when 2 users compete to answer an addition game. Thank you!!
Below is my client
My server thread
A user class for storing all the user involved.
Joined: Jun 01, 2010
OK. I have compiled your code. Please provide instructions on how to reproduce the error.
Joined: Jan 08, 2011
1) Run Q3Server program then run 2 instances of Q3Client program.
2) Press the play button for both the Q3Client programs.
3) It depends on different computer. Sometimes, you will catch EOFException at the Q3Server when the addition question is shown. If not, it will be shown after you play the second time. That mean you have submitted your answer and pressed the submit button when you see the question and then you played again by pressing the play button again for both Q3Client program. You will know you catch an exception because one of instance of the Q3Client textbox say that "The other player has left." That EOFException happens in the below line at Q3Server: