Java RMI practice
The basic RMI practice
- Place ComputingService.java, ComputingServiceImpl.java and RMIServer.java in the server.
- use javac to compile them
javac ComputingService.java javac ComputingServiceImpl.java javac RMIServer.java
- run it
java RMIServer
- if the default port 1099 is occupied, change it to an another port. In the 23rd line of RMIServer.java, then recomplie them and run.
// open RMIRegistry LocateRegistry.createRegistry(1099);
- Place ComputingService.java and RMIClient.java in client
- if your server and client isn't the same computer, change the "localhost" in 16th line of RMIClient.java to the ip address of your server
// get register from localhost:1099(host:port) Registry registry = LocateRegistry.getRegistry("localhost", 1099);
- use javac to compile them
javac ComputingService.java javac RMIClient.java
- run it and you will see an output 11
java RMIClient
Note: if you want to run it in a project, please give the two interface file (server and client) a same package name, or you will get an error: no security manager: RMI class loader disabled
A traditional client/server mode library.
- Place LibraryServer in server side
- Use javac to compile them
javac service\*.java javac LibraryServer.java
- Run it
java LibraryServer
- if the default port 1099 is occupied, change it to an another port in Line 18 of LibraryServer.java, then recompile them.
// open RMIRegistry LocateRegistry.createRegistry(1099);
- Place LibraryClient in client side
- If your server and client isn't the same computer, change the "localhost" in line 60 of view.MainController.java to the ip address of your server
// get register from localhost:1099 Registry registry = LocateRegistry.getRegistry("localhost", 1099);
- Use javac to compile them
javac -encoding utf-8 service\*.java javac -encoding utf-8 view\*.java javac -encoding utf-8 stage\*.java
- Run it and you will see the UI window
java stage.Main