• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Object streams and readers

 
Nirmal Mekala Kumar
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic