-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRMIServer.java
36 lines (31 loc) · 1.08 KB
/
RMIServer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;
public class RMIServer implements RMIInterface {
@Override
public void sendMessage(String s) throws RemoteException {
System.out.println(s);
}
@Override
public String getMessage(String text) throws RemoteException {
return "Your message is: " + text;
}
public static void main(String[] args) {
Registry reg = null;
try {
reg = LocateRegistry.createRegistry(1099);
} catch (Exception e) {
System.out.println("ERROR: Could not create the registry.");
e.printStackTrace();
}
RMIServer serverObject = new RMIServer();
System.out.println("Waiting...");
try {
reg.rebind("server", (RMIInterface) UnicastRemoteObject.exportObject(serverObject, 0));
} catch (Exception e) {
System.out.println("ERROR: Failed to register the server object.");
e.printStackTrace();
//Just add a sendMessage() method to your interface//
}
}
}