コード例 #1
0
  /** Destroys the server stored list. */
  @Override
  public void destroy() {
    stopped = true;

    try {
      if (connection != null) {
        connection.shutdownInput();
        connection.close();
        connection = null;
      }
    } catch (IOException e) {
    }

    try {
      if (connectionReader != null) {
        connectionReader.close();
        connectionReader = null;
      }
    } catch (IOException ex) {
    }

    if (connectionWriter != null) {
      connectionWriter.close();
      connectionWriter = null;
    }
  }
コード例 #2
0
  /** The logic that runs in separate thread. Dispatching responses. */
  public void run() {
    if (connection == null) {
      logger.error("No connection.");
      return;
    }

    try {
      connectionReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));

      if (!connectionReader.readLine().contains("XiVO")) {
        logger.error("Error xivo with server!");
        destroy();
        return;
      }

      String line;
      while ((line = connectionReader.readLine()) != null || !stopped) {
        try {
          if (logger.isTraceEnabled()) logger.trace("Read from server:" + line);

          handle((JSONObject) JSONValue.parseWithException(line));
        } catch (Throwable ex) {
          logger.error("Error parsing object:" + line, ex);
        }
      }
    } catch (IOException ex) {
      destroy();
    }
  }
コード例 #3
0
  /**
   * Connects to the server.
   *
   * @param serverAddress the address to connect, if null try to use our sip connection address.
   * @throws IOException
   */
  private void connect(String serverAddress) throws IOException {
    if (serverAddress != null) connection = new Socket(serverAddress, 5003);
    else // lets try using our sip connected address
    connection = new Socket(sipProvider.getConnection().getAddress().getAddress(), 5003);

    connectionWriter = new PrintStream(connection.getOutputStream());
  }