In an rmi-call, the involved objects are serialized and transmitted over an socket-stream. Is there a 'hook' to use different kind of stream? If a fast network link is used, the normal way might be adequate. if a modem link is used, a compressed stream might be better. Can an rmi socket connection detect and adapt to different speeds?

Thomas Auinger

Yes, there is some sort of 'hook'. The general strategy is to write your own subclass of and Next, modify the constructor of your remote object (the one that extends UnicastRemoteObject) to set a client and a server socket factory. These factories will be used by the remote object for RMI communication and thus using the input/output behaviour that was specified in the socket subclasses.

This approach has problems, as Scott McPherson pointed out:

"Many applications may require that data exchanged between client and server be encrypted, compressed, or handled in some other fashion. Doing this with RMI is simple enough, requiring only that you implement your own socket classes and an RMI socket factory that creates your special sockets. However, overriding the default socket factory disables RMI's ability to do HTTP tunneling, thereby preventing access by proxy server users."

Subclassing a Socket allows you to return your wanted stream when calling the Socket's getInputStream() and getOutputStream() methods:

public class MySocket extends
  public MySocket()
  { super();

  public MySocket(String host, int port)
  {  super(host, port);

  public InputStream getInputStream()
  { return new XXXXInputStream( super.getInputStream() );

  public OutputStream getOutputStream()
  { return new XXXXOutputStream( super.getOutputStream() );

The following code shows how to subclass a ServerSocket.

public class MyServerSocket extends
  public MyServerSocket(int port)
  { super(port);

  public Socket accept()
  { Socket socket = new MySocket();
     return socket;
More (and detailed) Information can be found at

Creating a Custom RMI Socket Factory at

I couldn't think of any way, how to "detect the speed of an rmi socket connection". Definitely not by provided means. Furthermor, you never know if the current connection is slow or if the net is simply blocked/slow at the moment.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact