Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 28th, 2012  |  syntax: None  |  size: 0.76 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Localhost-only RMI?
  2. import java.io.IOException;
  3. import java.net.*;
  4. import java.rmi.server.*;
  5. import java.rmi.registry.LocateRegistry;
  6.  
  7. public class RestrictedRMIRegistry implements RMIServerSocketFactory {
  8.     public static void main(String... args) throws IOException {
  9.         int port = (args.length == 0 ? 1099 : Integer.parseInt(args[0], 10));
  10.         RMIClientSocketFactory csf = RMISocketFactory.getDefaultSocketFactory();
  11.         RMIServerSocketFactory ssf = new RestrictedRMIRegistry();
  12.  
  13.         LocateRegistry.createRegistry(port, csf, ssf);
  14.     }
  15.  
  16.     public ServerSocket createServerSocket(int port) throws IOException {
  17.         // Tricky bit; make a server socket with bound address
  18.         return new ServerSocket(port, 0, InetAddress.getLocalHost());
  19.     }
  20. }