File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads and I/O stream

 
Micky Wong
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, all,
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.

Thank you in advance for assistance.
 
Tom Reilly
Rancher
Posts: 618
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post your code?
 
Micky Wong
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


My server


A user class for storing all the user involved.
 
Tom Reilly
Rancher
Posts: 618
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK. I have compiled your code. Please provide instructions on how to reproduce the error.
 
Micky Wong
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:


 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic