aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes error sending serialized object between client and server using sockets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "error sending serialized object between client and server using sockets" Watch "error sending serialized object between client and server using sockets" New topic
Author

error sending serialized object between client and server using sockets

Chris Brat
Ranch Hand

Joined: May 22, 2003
Posts: 108
Hi,
I have an object from class
class MyObject implements Serializable{
...
...
}

and a client with this little snippet in it with the necessary values for ip and port so that a connection is created.

Socket socket = new Socket(ipiString, port);
ObjectOutputStream os = new ObjectOutputStream(socket.getOutputStream());
ObjectInputStream is = new ObjectInputStream(socket.getInputStream());
os.writeObject(new MyObject);
then on my server is this snippet

ServerSocket socket = new ServerSocket(port);
Socket clientSocket = socket.accept();
ObjectOutputStream os = new ObjectOutputStream(clientSocket.getOutputStream());
ObjectInputStream is = new ObjectInputStream(clientSocket.getInputStream());
MyObject obj = (MyObject)is.readObject();

Everything goes fine until the object gets read at the server - a ClassCastException is generated... even if I only try to accept the Object object from is.readObject().
I am guessing that the problem is with my object serialization?
Any suggestions?


SCJP 1.2, SCJP 5, SCBCD
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Can you give us the error message (a ClassCastException always tells you the offending class name, which would be useful for us to know), the stack trace, and the snippet of your code where the stacktrace indicates the problem is?
- Peter
[ May 23, 2003: Message edited by: Peter den Haan ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: error sending serialized object between client and server using sockets