• Post Reply Bookmark Topic Watch Topic
  • New Topic

java.io. StreamCorruptedException: invalid stream header  RSS feed

 
Stanley George
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
My code runs correctly when i run the clients one after another without using threads.
I am getting this following error when i run my multi-threaded server. When a server accepts a client connection, ClientHandler is the thread that handles that client.
Exception in thread "main" java.io.StreamCorruptedException: invalid stream header
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:737)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:253)
at comm.DOMTransfer.<init>(DOMTransfer.java:25)
at ClientHandler.<init>(ClientHandler.java:18)
at GridInfo.main(GridInfo.java:34)
This is where the error occurs:
input = new ObjectInputStream(socket.getInputStream());
Thank you for your time.
Stanley George
 
Joe Ess
Bartender
Posts: 9429
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've seen such behavior before. I think it is related to this:

The ObjectInputStream constructor blocks until it completes reading the serialization stream header. Code which waits for an ObjectInputStream to be constructed before creating the corresponding ObjectOutputStream for that stream will deadlock, since the ObjectInputStream constructor will block until a header is written to the stream, and the header will not be written to the stream until the ObjectOutputStream constructor executes. This problem can be resolved by creating the ObjectOutputStream before the ObjectInputStream, or otherwise removing the timing dependency between completion of ObjectInputStream construction and the creation of the ObjectOutputStream.

Java Object Serialization Specification
 
Pablo Dias
Greenhorn
Posts: 2
Firefox Browser Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please, check if you are using the same kind of stream in both sides of connection. If you are using ObjectOutputStream in one side, the other should use ObjectInputStream for reading and so on!

I got this same error the first experiment I tried, when absently I had used PrintStream and ObjectInputStream.... There's no chance of working this way!

Share if it was the problem!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!