Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jun 1st, 2012  |  syntax: Java  |  size: 2.20 KB  |  views: 167  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /*Same interface i have in my server computer.*/
  2. package remoto;
  3. import java.rmi.Remote;
  4. import java.rmi.RemoteException;
  5.  
  6. public interface Mensageiro extends Remote {
  7.     void enviarMensagem(String msg) throws RemoteException;
  8.     String lerMensagem() throws RemoteException;
  9. }
  10. /**********************************************************************************************/
  11. import remoto.*;
  12. import java.rmi.registry.LocateRegistry;
  13. import java.rmi.registry.Registry;
  14. import java.rmi.RemoteException;
  15. import java.rmi.NotBoundException;
  16. public class MensageiroCliente {
  17.  
  18.     public static void main(String[] args) {
  19.         try {
  20.             Registry registry = LocateRegistry.getRegistry("192.168.1.102");
  21.             Mensageiro m = (Mensageiro) registry.lookup("MensageiroServer");
  22.             String resposta = m.lerMensagem();
  23.             System.out.println("Resposta do Server: " + resposta);
  24.         }  catch (RemoteException e) {
  25.             System.out.println();
  26.             System.out.println("RemoteException: " + e.toString());
  27.         } catch (NotBoundException e) {
  28.             System.out.println();
  29.             System.out.println("NotBoundException: " + e.toString());
  30.         } catch (Exception e) {
  31.             System.out.println();
  32.             System.out.println("Exception: " + e.toString());
  33.         }
  34.     }
  35. }
  36. /**********************************************************************************************/
  37. Error1:
  38. NotBoundException: java.rmi.NotBoundException: MensageiroServer
  39. /**********************************************************************************************/
  40. Error2: Changing a little bit the string of LocateRegistry.getRegistry and adding the port "192.168.1.102:1099"
  41.  
  42. RemoteException: java.rmi.UnknownHostException: Unknown host: 192.168.1.102:1099; nested exception is:
  43.         java.net.UnknownHostException: 192.168.1.102:1099
  44. /**********************************************************************************************/
  45. I'm using Mint, with NetBeans 6.9 and typing java -version in terminal it appears:
  46. java version "1.6.0_20"
  47. OpenJDK Runtime Environment (IcedTea6 1.9.13) (6b20-1.9.13-0ubuntu1~10.10.1)
  48. OpenJDK Client VM (build 19.0-b09, mixed mode, sharing)
clone this paste RAW Paste Data