void (final boolean localHostOnly) { // this properties are necessary for RMI servers to work in some cases: // if we are behind a firewall, if the network connection is lost, etc. // do not use domain or http address for server if (System.getProperty(SERVER_HOSTNAME) == null) { System.setProperty(SERVER_HOSTNAME, getLoopbackAddress()); } // do not use HTTP tunnelling System.setProperty("java.rmi.server.disableHttp", "true"); if (RMISocketFactory.getSocketFactory() != null) return; try { RMISocketFactory.setSocketFactory(new RMISocketFactory() { final InetAddress loopbackAddress = InetAddress.getByName(getListenAddress(localHostOnly)); @Override public Socket createSocket(String host, int port) throws IOException { Socket socket = new Socket(host, port); socket.setKeepAlive(true); return socket; } @Override public ServerSocket createServerSocket(int port) throws IOException { return new ServerSocket(port, 0, loopbackAddress); } }); } catch (IOException e) { throw new AssertionError(e); } }