示例#1
0
 public void disconnect() {
   connected = false;
   try {
     if (rmiServer != null && index > -1) {
       rmiServer.stopViewer(index);
       // UnicastRemoteObject.unexportObject(rmiServer, true);
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   rmiServer = null;
   registry = null;
 }
示例#2
0
  public int connect() {
    connected = false;

    try {
      if (clientConfig.ssl_enabled)
        registry =
            LocateRegistry.getRegistry(
                clientConfig.server_address,
                clientConfig.server_port,
                new SslRMIClientSocketFactory());
      else
        registry =
            LocateRegistry.getRegistry(clientConfig.server_address, clientConfig.server_port);

      rmiServer = (ServerInterface) registry.lookup("jrdesktop");

      /* rmiServer = (ServerInterface) Naming.lookup(
       "rmi://" + clientConfig.server_address + ":" +
      clientConfig.server_port + "/jrdesktop");*/

      index =
          rmiServer.startViewer(
              InetAdrUtility.getLocalHost(),
              clientConfig.username,
              PasswordUtility.encodeString(clientConfig.password),
              clientConfig.reverseConnection);

      switch (index) {
        case -1:
          JOptionPane.showMessageDialog(
              null, "Authentication failed !!", "Error !!", JOptionPane.ERROR_MESSAGE);
          return -1;
        case -2:
          JOptionPane.showMessageDialog(
              null, "Reverse connection failed !!", "Error !!", JOptionPane.ERROR_MESSAGE);
          return -1;
      }

      displayStatus();
      connected = true;
      return index;
    } catch (Exception e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(null, e.getMessage(), "Error !!", JOptionPane.ERROR_MESSAGE);
      return -1;
    }
  }