This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jun 1st, 2012  |  syntax: Java  |  size: 1.87 KB  |  views: 231  |  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. package remoto;
  2. import java.rmi.Remote;  
  3. import java.rmi.RemoteException;
  4. public interface Mensageiro extends Remote {
  5.  
  6.     void enviarMensagem(String msg) throws RemoteException;
  7.  
  8.     String lerMensagem() throws RemoteException;
  9.    
  10. }
  11. /**********************************************************************************************/
  12. package remoto;
  13. import java.rmi.RemoteException;
  14. import java.rmi.server.UnicastRemoteObject;
  15. public class MensageiroImpl extends UnicastRemoteObject implements Mensageiro {
  16.  
  17.     public MensageiroImpl() throws RemoteException {
  18.         super();
  19.     }
  20.  
  21.     @Override
  22.     public void enviarMensagem(String msg) throws RemoteException {
  23.         System.out.println(msg);
  24.     }
  25.  
  26.     @Override
  27.     public String lerMensagem() throws RemoteException {
  28.         return "Ola mundo meu ovo!";
  29.     }
  30.    
  31. }
  32. /**********************************************************************************************/
  33. import remoto.*;
  34. import java.rmi.registry.Registry;
  35. import java.rmi.registry.LocateRegistry;
  36. import java.rmi.Naming;
  37. import java.rmi.server.*;
  38. public class MensageiroServer {
  39.     public static void main(String[] args) {
  40.         try {
  41.             MensageiroImpl m = new MensageiroImpl();
  42.             LocateRegistry.createRegistry(1099);
  43.             Registry registro = LocateRegistry.getRegistry();
  44.             registro.bind("MensageiroService", m);
  45.             System.out.println("Servidor no ar.");
  46.         } catch (Exception e) {
  47.             System.out.println("Erro no servidor: " + e);
  48.         }
  49.     }
  50. }
  51. /**********************************************************************************************/
  52. I'm using Mint,with NetBeans 7.1.2 and typing java -version in terminal it appears:
  53. java version "1.6.0_26"
  54. Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
  55. Java HotSpot(TM) Client VM (build 20.1-b02, mixed mode, sharing)
clone this paste RAW Paste Data