Forums Register Login

streams connection to socket

+Pie Number of slices to send: Send
Hi
can i use same socket output stream for two different purposes let's say
once i write some string to it
next time i want to write some serialized object to it.
is it possible.
my approach was
PrintStream p = new PrintStream(socket.getOutputStream());

p.println("-------------");
p = null;
ObjectOutputStream o = new ObjectOutputSream socket.getOutputStream());
o.writeObject(object);

its not working.
plz.help me where am i wrong.
thanx
harish
+Pie Number of slices to send: Send
Hi,
You are perfectly correct. You can always do that provided the objects you are writing to the stream implements the seriablizable interface....otherwise you will get an error. The problem is in the Object you are trying to write to the output stream .
Only objects that support the java.io.Serializable interface can be written to streams.
Refer to this link for more info http://java.sun.com/j2se/1.3/docs/api/java/io/ObjectOutputStream.html
Thats it

Originally posted by Harish Kashyap:
Hi
can i use same socket output stream for two different purposes let's say
once i write some string to it
next time i want to write some serialized object to it.
is it possible.
my approach was
PrintStream p = new PrintStream(socket.getOutputStream());

p.println("-------------");
p = null;
ObjectOutputStream o = new ObjectOutputSream socket.getOutputStream());
o.writeObject(object);

its not working.
plz.help me where am i wrong.
thanx
harish


Who among you feels worthy enough to be my best friend? Test 1 is to read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 777 times.
Similar Threads
trouble retrieving html of all web sites
Random EOFException - runs for minutes, hours or days and then suddenly throws this (sometimes)
Java client socket to talk to C server socket
Unable to send data.
how to exchange binary data between applet and server socket
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 07:11:53.