• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Object streams and readers

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can I have objectinputstream and a bufferedreader both open on a single socket connection, between same client and server at the same time.

client = new Socket(ip,4444);
out= new PrintWriter(client.getOutputStream(),true);
in= new BufferedReader(new InputStreamReader(client.getInputStream()));
ObjectInputStream ois = new ObjectInputStream(client.getInputStream());

I tried this but i'm getting the following exception
{
java.io.StreamCorruptedException: invalid stream header
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:753)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:268)
at com.SearchClient$SearchThread.run(SearchClient.java:86)
at java.lang.Thread.run(Thread.java:595)
}

If i cannot have both a stream and a reader open on same socket, could anyone please suggest how i pass different kind of data between my server and client. The situation is : I want normal string based communication for requests and acknowledgements (like "open", "ok","process","ok" etc) and also able to send an object(array) over the stream.
Please help me out.
 
reply
    Bookmark Topic Watch Topic
  • New Topic