Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

StreamCorruptedException on ObjectInputStream attached to socket- Linux only

2 views
Skip to first unread message

Paul Folbrecht

unread,
Apr 19, 2001, 10:48:58 PM4/19/01
to
The following problem occurs on RH Linux 7 with Sun JDK 1.3 but not on
any Window platform (with JDK 1.3):

At times I get a StreamCorruptedException when trying to read via an
ObjectInputStream attached to a Socket:

java.io.StreamCorruptedException: InputStream does not contain a
serialized object
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:849)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:168)
...

It's some kind of timing issue- it only occurs if the sender begins the
send *before* the receiver calls getInputStream() on the socket. The
object being sent through the stream is perfectly valid (in fact in most
cases it's nothing but an Integer).

Would appreciate any advice from someone who might have encountered this
problem before.

-Paul

Paul Folbrecht

unread,
Apr 19, 2001, 10:56:11 PM4/19/01
to
Paul Folbrecht wrote:

Mistake above- I meant to say that the problem only occurs if the
receiver calls getInputStream() before the sender begins the send. This
makes me think that possibly getInputStream() isn't blocking as it
should and is somehow getting garbage data.


Gordon Beaton

unread,
Apr 20, 2001, 1:37:56 AM4/20/01
to

Can you show the code where you make the socket connection and create
both ends of the ObjectStream? Are you doing anything else with the
socket other than creating the ObjectStreams at both ends?

This simple example works fine for me on Linux (linux 2.2.19,
glibc2.1.2, Sun JDK 1.3.0):

server:
ServerSocket ss = new ServerSocket(43210);
Socket s = ss.accept();
ObjectInputStream ois = new ObjectInputStream(s.getInputStream());
Integer foo = (Integer)ois.readObject();
ois.close();


client:
Socket s = new Socket("localhost",43210);
ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream());
oos.writeObject(new Integer(47));
oos.close();

Letting either the client or the server sleep before creating the
streams makes no difference to the results I get.

/gordon

--
[ do not send me private copies of your followups ]
g o r d o n . b e a t o n @ e r i c s s o n . c o m
ericsson research
stockholm, sweden

0 new messages