Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Client server synchronization problem

843790Feb 6 2007 — edited Feb 7 2007
I have a client and server connected with ObjectOutputStream to ObjectInputStream pairs flowing in both directions over a TCP connection. The client writes two objects and tries to read on object from the server. The server reads two objects and then writes an object to the client.

Through debug statements, I've found that the server successfully reads the two objects from the client and completes its writeObject() call back to the client. But the client blocks forever trying to read the object that the server wrote to the stream. It seems simple enough to synchronize these reads and writes, but I'm obviously missing something important. I don't understand why the client can't read the callback.

Here are the relevant sections of the client and server code:

Client code:
			out = tcpSock.getOutputStream();
			oos = new ObjectOutputStream(out);
			oos.writeObject(new String("password"));
			oos.writeObject(fileBase);
			in = tcpSock.getInputStream();
			ois = new ObjectInputStream(in);
			connectStatus = (Integer)ois.readObject();//client hangs here
                        oos.writeObject(bos.toByteArray());[
			
Server code:
                        in = tcpConnection.getInputStream();
			ois = new ObjectInputStream(in);
			password = (String) ois.readObject();
			fileName = (String) ois.readObject();
			out = tcpConnection.getOutputStream();
			oos = new ObjectOutputStream(out);
			oos.write(new Integer(0));//last statement executed by server
			fileAsByteArray = (byte[])ois.readObject();
			
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 7 2007
Added on Feb 6 2007
4 comments
92 views