Two Laptop Bag
The moose likes Sockets and Internet Protocols and the fly likes Object streams and readers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Object streams and readers" Watch "Object streams and readers" New topic

Object streams and readers

Nirmal Mekala Kumar
Ranch Hand

Joined: Aug 27, 2005
Posts: 63
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
{ invalid stream header
at com.SearchClient$

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.

Nirmal Kumar<br />If you have to aim, aim for the moon. Even if you miss you will land among the stars
I agree. Here's the link:
subject: Object streams and readers
jQuery in Action, 3rd edition