/** Modified by Gabriele Bianchi 04/01/2006 */
  public void run() {
    StringBuffer connectorStringBuffer;
    if (Datas.isSSL) {
      connectorStringBuffer = new StringBuffer("ssl://");
    } else {
      connectorStringBuffer = new StringBuffer("socket://");
    }
    connectorStringBuffer.append(_hostname);
    connectorStringBuffer.append(":");
    connectorStringBuffer.append(_port);
    connectorStringBuffer.append("");

    String connectorString = connectorStringBuffer.toString().trim();
    System.out.println(connectorString);
    try {
      if (Datas.isSSL) {
        connection = (SecureConnection) Connector.open(connectorString);
      } else {
        connection = (StreamConnection) /*Connector.open*/ getConnectionForRequest(connectorString);
      }
      if (connection != null) {
        SocketConnection sc = (SocketConnection) connection;
        sc.setSocketOption(SocketConnection.KEEPALIVE, 2);
      }

      _cm.notifyConnect(connection, this.openInputStream(), this.openOutputStream());
    } catch (Exception e) {
      e.printStackTrace();
      System.out.println("Connessione non riuscita:" + e.getMessage());
      _cm.notifyNoConnectionOn("I can't connect, server is unreachable");
      DebugStorage.getInstance().Log(0, "Can't connect, server is unreachable", e);
    }

    return;
  }
  private void runLoopbackTest(String url) throws IOException {
    System.out.println("Connecting to " + url);
    SocketConnection sc = (SocketConnection) Connector.open(url);

    try {
      sc.setSocketOption(SocketConnection.LINGER, 5);

      InputStream is = sc.openInputStream();
      OutputStream os = sc.openOutputStream();

      String testData = "OK\r\n";

      os.write(testData.getBytes());
      os.flush();

      StringBuffer buf = new StringBuffer();

      int ch = 0;
      int count = 0;
      while (ch != -1) {
        ch = is.read();
        buf.append((char) ch);
        count++;
        if (count >= testData.length()) {
          break;
        }
      }

      assertEquals("Data received", buf.toString(), testData);

      is.close();
      os.close();
    } finally {
      sc.close();
    }
  }