• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Socket and DataOutputStream

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
You know it is dark times when the trees riot. I think this tiny ad is their leader:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic