Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to send any java Object through socket?  RSS feed

 
Parshuram Walunjkar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everybody,
I want know how to send any java Object through socket i.e. send Object through socket from client side and read it to the server side and vice versa.
Please suggest solution me.
Regards From Parshuram
 
Les Dsouza
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To send an object thru a stream you need to serialize it ie.. the object should implement the serializable interface; this is a 'marker' interface hence you dont need to define any methods.
All objects that support the java.io.Serializable interface can be written to streams.
TO send the object you use an ObjectOutputStream - call its writeObject method, Likewise to read you use the ObjectInputStream's readObject method.
Hope the code below helps -

[ February 04, 2002: Message edited by: Les Dsouza ]
[ February 04, 2002: Message edited by: Les Dsouza ]
 
Parshuram Walunjkar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am sending Object from server to client it receive to the client side but I am doing that hole thing in thread so it gives exception such as streamCorrecuptedException
Why such exception occurs?
Please help me
From
Parshuram Walunjkar
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!