Java Creating a new ObjectInputStream Blocks

Just to expand on FatGuy’s answer for other Googlers that find this; the solution to this “chicken and egg problem” is to have each side open the output stream first, flush the output stream, and then open the input stream.

ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());
out.flush();
ObjectInputStream in = new ObjectInputStream(socket.getInputStream());

Leave a Comment