• Post Reply Bookmark Topic Watch Topic
  • New Topic

Socket and DataOutputStream

 
Abhijeet Gholkar
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public void openStreams() throws IOException
{
InputStream in = clientsock.getInputStream();
OutputStream out =
clientsock.getOutputStream();
din = new DataInputStream(in);
dout = new DataOutputStream(out);
oout = new ObjectOutputStream(out);
oin = new ObjectInputStream(in);
in = null;
out = null;
isstreamopen = true;
}
The italicized piece of the above code throws java.io.StreamCorruptedException. I have got no idea why this is happening as all the streams opened before that open successfully.
[ June 21, 2002: Message edited by: Gholkar Raja ]
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, was your stream written using an ObjectOutputStream, and if so, did you perhaps construct output streams in a different order? Look in the source for java.io.ObjectInputStream: the constructor calls readStreamHeader() and throws a StreamCorruptedException if the header cannot be found. Apparently that is the case here. This header is normally written to the stream by the ObjectOutputStream constructor so unless you didn't use one, or wrote data into the stream before creating it, the header should be there.

- Peter
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!