java rmi example client server

Solutions on MaxInterview for java rmi example client server by the best coders in the world

showing results for - "java rmi example client server"
Erika
05 Jan 2018
1package com.mkyong.rmiinterface;
2
3import java.rmi.Remote;
4import java.rmi.RemoteException;
5
6public interface RMIInterface extends Remote {
7
8    public String helloTo(String name) throws RemoteException;
9
10}
María Fernanda
13 Mar 2019
1package com.mkyong.rmiserver;
2
3import java.rmi.Naming;
4import java.rmi.RemoteException;
5import java.rmi.server.UnicastRemoteObject;
6
7import com.mkyong.rmiinterface.RMIInterface;
8
9public class ServerOperation extends UnicastRemoteObject implements RMIInterface{
10
11    private static final long serialVersionUID = 1L;
12
13    protected ServerOperation() throws RemoteException {
14
15        super();
16
17    }
18
19    @Override
20    public String helloTo(String name) throws RemoteException{
21
22        System.err.println(name + " is trying to contact!");
23        return "Server says hello to " + name;
24
25    }
26
27    public static void main(String[] args){
28
29        try {
30
31            Naming.rebind("//localhost/MyServer", new ServerOperation());
32            System.err.println("Server ready");
33
34        } catch (Exception e) {
35
36            System.err.println("Server exception: " + e.toString());
37            e.printStackTrace();
38
39        }
40
41    }
42
43}