Код | import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; public class Client { private Client() {} public static void main(String[] args) { String host = (args.length < 1) ? null : args[0]; try { Registry registry = LocateRegistry.getRegistry("127.0.0.1",8180); Hello stub = (Hello) registry.lookup("Hello"); String response = stub.sayHello(); System.out.println("response: " + response); } catch (Exception e) { System.err.println("Client exception: " + e.toString()); e.printStackTrace(); } } }
|
Код | import java.rmi.RemoteException; import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; import java.rmi.server.UnicastRemoteObject; public class Server extends UnicastRemoteObject implements Hello { public Server() throws RemoteException{} public String sayHello() { return "Hello, world!"; } public static void main(String args[]) { try { Hello stub = (Hello) new Server(); // Bind the remote object's stub in the registry Registry registry = LocateRegistry.createRegistry(8180); registry.rebind("Hello", stub); System.err.println("Server ready"); } catch (Exception e) { System.err.println("Server exception: " + e.toString()); e.printStackTrace(); } } }
|
немного подправил, теперь работает. |