• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating Instance of ObjectInput Halting the Program.(No error but program Does not proceed)

 
Udit Upadhayay
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I passed a object from Client to Server Using ObjectInput and ObjectOutput and Displaying it on Server Console. It Worked.

Now I want to pass the Objcet Back to the Client and Display it on the client Console.

So I made Few Changes
1. Created an infinite loop in server so I don't Need to Run the Server Again and Again(Not Related To problem but I Don't Know Where problem is So I thought it would be better to mention it).
2. Created an ObjectInput in the client Class Constructor to Recieve the Object.

To check when I run It. It halted and nothing happened.

To locate the Source of Problem I inserted Some System.out.println(" Vague message") in code and found that the in client program
1. System.out.println("Input Stream Created"); --> is printed SuccessFully
2. System.out.println("Associating Input Stream"); -->is not printed.
this means the readClientSocket = new ObjectInputStream(sockIn); is not returning.

I can't figure Out Why.

Here is the Source Program

/*Client*/


/*Server Code */


Why the new ObjectInputStream(sockIn) is causing program to halt. I mean it should return null or some Exception.
Any Ideas???
 
Udit Upadhayay
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
readClientSocket = new ObjectInputStream(sockIn); is in Client Class constructor and I have also TestObj Class is Visible to both Client and Server
 
Tony Docherty
Saloon Keeper
Posts: 3144
72
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

I've added code tags to your post to make it easier to read.

The problem you have is when you create an ObjectInputStream passing in an InputStream it blocks as per the API docs:
Creates an ObjectInputStream that reads from the specified InputStream. A serialization stream header is read from the stream and verified. This constructor will block until the corresponding ObjectOutputStream has written and flushed the header.

As both your Server and Client create an ObjectInputStream they are waiting for each other to write and flush their respective input streams.
 
Udit Upadhayay
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tony.
I moved the Constructor to the place where I was actually hoping to receive the Object and that solved the problem.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!