wood burning stoves 2.0*
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
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Object streams and readers" Watch "Object streams and readers" New topic
Author

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
{
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.


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: http://aspose.com/file-tools
 
subject: Object streams and readers