Posted By:
Mikael_Jakobsson
Posted On:
Wednesday, November 21, 2001 04:21 AM
It is not the class that is serialized and passed over the network, it is the data in the instance, which is why it doesn't matter that the class is available on both client and server.
All objects passed via RMI are serialized before they are sent over the network. This also means that all the data in the object (i.e. all member variables) are also serialized.
Thus, if an object contains a reference to a Socket, the Socket will also be serialized when the object is passed as a parameter from the client to the server (or returned from the server to the client).
Sockets contain a reference to a SocketImpl object, which also will be serialized and passed over the network. It is hard from the problem description to be sure, but I think that it is this behaviour you are noticing.
A socket created on one side (server/client) is normally not of any use at all to the other side. Therefore such members should be prevented from being serialized.
This prevention can be done by declaring the member variable as transient:
public class MyClass implements java.io.Serializable {
private transient Socket mySocket; // This is not serialized
private int otherData;
// etc etc
}