Ejemplo n.º 1
0
  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;
    }
  }
Ejemplo n.º 2
0
 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);
   }
 }
Ejemplo n.º 3
0
  /**
   * Connect to the server
   *
   * @return true if connected, false otherwise
   */
  public boolean connect(int clientIndex) {

    if (logger.isTraceEnabled()) {
      logger.trace("connecting to " + this.hostAddress + ":" + this.port);
    }

    ConnectFuture future =
        connector.connect(
            new InetSocketAddress(this.hostAddress, this.port),
            new MinaClientHandler(clientIndex, clientPrefix, minaIdletime),
            cfg);
    future.join();
    if (!future.isConnected()) {
      logger.error("Unable to connect to " + this.hostAddress + ":" + this.port);
      return false;
    } else {

      IoSession session = future.getSession();
      sessions.add(session);
      logger.info("Connected to " + this.hostAddress + ":" + this.port);
      return true;
    }
  }