public static Remote exportObject(Remote obj) throws RemoteException {
  int port=2000;
  port+=Randomness.nextInt(20000);
  final int TRIES=100;
  for (int i=0; i < TRIES; i++) {
    try {
      int candidatePort=port + i;
      return UnicastRemoteObject.exportObject(obj,candidatePort);
    }
 catch (    RemoteException e) {
    }
  }
  return UnicastRemoteObject.exportObject(obj,port);
}

public static Remote exportObject ( Remote obj ) throws RemoteException { int port = 2000 ; port += Randomness . nextInt ( 20000 ) ; final int TRIES = 100 ; for ( int i = 0 ; i < TRIES ; i ++ ) { try { int candidatePort = port + i ; return UnicastRemoteObject . exportObject ( obj , candidatePort ) ; } catch ( RemoteException e ) { } } return UnicastRemoteObject . exportObject ( obj , port ) ; }
this is a wrapper over unicastremoteobject . exportobject , as it does not properly handle anonymous / ephemeral ports . in particular , " exportobject ( remote obj ) " returns a remotestub , and not a remote reference .
