• Post Reply Bookmark Topic Watch Topic
  • New Topic

Through the socket !!  RSS feed

 
Amitkumar Dhama
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all ranchers,
this is my first mail to this section and my question is...

how to send an object through the socket

there are two members, string and int (name and age)in the class and i have receive the object and print the name and age on the server side...

tell me hw to solve the problem..
I know that this is not a very big problem. if u will give me some clue of hw to solve it or which good material to follow for this. i shall be thankfull to you..

thanking in advance...
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you are talking about is serialization - converting the object data to a stream and reconstructing it on the other end.
You need to get familiar with classes in the java.io package

First - your object must be Serializable see the Serializable interface docs
Next - you need to learn how to write it to an ObjectOutputStream and read it with an ObjectInputStream.

I suggest you first serialize an object to a file and read it back before trying to send it through a socket.

Finally you will be ready to work with a stream attached to a socket. Note that the receiving machine MUST have access to a copy of the class file for the object in order to construct it.
Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!