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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

java.io.StreamCorruptedException: invalid stream header

843790Jul 11 2007 — edited Jul 12 2007
I am having a problem with sending two objects (over a socket). I have read in other posts that this could be due to trying to receive incompatible data types but my applications work fine if I send my objects synchronously rather than asynchronously.

I will try my best to describe what my problem is as my code is very long.

I have a server and a client application (2 apps). Multiple clients connect to the server and send their details (as an object) to the server. The server then amends the object (adds some more data) and sends it back to the clients. Both the SendObject and ReceiveObject class are threads and I have created a Listener (within the client) that activates when an object is received (asynchronous communication). The Listener method looks to see if the event is an instance of a particular class and casts is as appropriate (as per below).
public void receivedObject(ReceivedObjectEvent e) {
	ReceiveObjectThread obj = (ReceiveObjectThread) e.getObject();
	if(obj.getObject() instanceof Player) {
		thePlayer = (Player) obj.getObject();
		theTable.setHandData(thePlayer.getHand());
	}
	if(obj.getObject() instanceof GameData) {
		gameData = (GameData) obj.getObject();
		theTable.setPlayerList(gameData.getOpponents());
	}
}
The objects that are passed between applications both implement Serializable.
This all works fine synchronously object passing. However, if I try and spawn two sendObject threads within the server and the corresponding two receive threads within the client and wait for the Listener to activate (asynchronously) I get the following error:
java.io.StreamCorruptedException: invalid stream header: 00057372
	at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:783)
	at java.io.ObjectInputStream.<init>(ObjectInputStream.java:280)
	at ReceiveObjectThread.run(ReceiveObjectThread.java:84)
java.io.StreamCorruptedException: invalid stream header: ACED0006
	at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:783)
	at java.io.ObjectInputStream.<init>(ObjectInputStream.java:280)
	at ReceiveObjectThread.run(ReceiveObjectThread.java:84)
 
I am sure that this problem is due to my limited knowledge on socket and data transfer. Therefore any help on this one will be gratefully received.

Comments

Mohamed Amin

Excellent work, Many thanks for this chapter,

Mohamed  Amin

1 - 1
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Aug 9 2007
Added on Jul 11 2007
3 comments
3,300 views