The client socket factory is being passed back and forth across the network.
1 posts in topic
Flat View  Flat View

Posted By:   Paul_Beadle
Posted On:   Thursday, May 24, 2001 07:02 AM

I am using server and client socket factories on my RMI servers, and am finding that making a connection from a client will cause the client socket factory to be serialized and sent from the server to the client. Is there a way of preventing this? The application is a client/server one and the client and server use the same jar file. I don't understand why the factory needs to be passed across the network.

Re: The client socket factory is being passed back and forth across the network.

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


About | Sitemap | Contact