• Post Reply Bookmark Topic Watch Topic
  • New Topic

streams connection to socket

 
Harish Kashyap
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Nagalinga Murthy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!