Today I’ve got an problem with an ObjectStream (Input and also Output).
I used the Input and OutputStream which came directly out of the socket.
While initialising the streams my runs and runs and runs. With no error message.
I got no error message.
It seems that the constructor of the ObjectInputStream runs endless…
Here is the code where the problem exists.
socket.isConnected was true.
ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
Any ideas?
The object input stream reads the header sent by the object output stream which is it constructed. If you haven’t sent the header, it will wait forever.
The simple solution is to ALWAYS create the object output stream first and flush it before creating the object input stream.