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();