Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Server.java
- import java.rmi.Remote;
- import java.rmi.Naming;
- import java.rmi.server.UnicastRemoteObject;
- interface Interf extends Remote{
- public String sayHello(String name) throws Exception;
- }
- class Implementation extends UnicastRemoteObject implements Interf{
- Implementation() throws Exception{
- System.out.println("An instance of the Server is running.");
- }
- public String sayHello(String name) throws Exception{
- return " Hello "+name+"!";
- }
- }
- public class Server{
- public static void main(String args[]){
- try{
- Naming.rebind("AnythingYouWant", new Implementation());
- } catch(Exception e){e.printStackTrace();}
- }
- }
- //Client.java
- import java.rmi.Naming;
- import java.util.Scanner;
- public class Client{
- public static void main(String[] args){
- try{
- Scanner sc = new Scanner(System.in);
- Interf interf = (Interf)Naming.lookup("rmi://localhost/AnythingYouWant");
- System.out.println(interf.sayHello(sc.next()));
- } catch(Exception e){e.printStackTrace();}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement