public boolean reconnect() { try { Logger.println("Attempting to connect to LS"); SocketConnector conn = new SocketConnector(); SocketConnectorConfig config = new SocketConnectorConfig(); ((SocketSessionConfig) config.getSessionConfig()).setKeepAlive(true); ((SocketSessionConfig) config.getSessionConfig()).setTcpNoDelay(true); ConnectFuture future = conn.connect( new InetSocketAddress(Config.LS_IP, Config.LS_PORT), connectionHandler, config); future.join(3000); if (future.isConnected()) { session = future.getSession(); Logger.println("Registering world (" + Config.SERVER_NUM + ") with LS"); actionSender.registerWorld(); connectionAttempts = 0; return true; } if (connectionAttempts++ >= 100) { Logger.println("Unable to connect to LS, giving up after " + connectionAttempts + " tries"); System.exit(1); return false; } return reconnect(); } catch (Exception e) { Logger.println("Error connecting to LS: " + e.getMessage()); return false; } }
public void connect() { ConnectFuture connectFuture = connector.connect(new InetSocketAddress(host, port), this); connectFuture.join(5000); try { session = connectFuture.getSession(); } catch (RuntimeIOException e) { engine.error(e); } }