A quick RMI and CORBA refresher. In RMI, the RMI Compiler (rmic) is used to create Java specific binary glue code from the server binary class (es); the glue code generated is also called client side stubs and server side skeletons. Server side RMI skeletons are no longer required for JDK 1.2 or later, the RMI runtime can create skeletons dynamically.
A simple example of a Java-RMI setup using Maven
Project Setup
![Java rmi example programs Java rmi example programs](https://www.codeproject.com/KB/java/884158/extracted-png-image5.png)
There are three subprojects in this example: RMIClient, RMIServer, and RMIInterfaces. These should be self-explanatory. The server sets up a basic class to be used as a remote object. The client then connects to it. Since both the client and the server need to be able to know the definition of the interface, that is broken out into a separate project that they both have as a dependency.
This project should build out of the box with Maven.
Running the project
Running this can be a somewhat involved task, but here's the simple way to do it:
- Run the rmiregistry program. This should be in $JAVA_HOME/bin.
rmiregistry -J-Djava.rmi.server.useCodebaseOnly=false
- Run the RMIServer. Make sure that when setting the RMI server codebase, the path ends with a /, otherwise it will not work.
java -Djava.rmi.server.useCodebaseOnly=false -Djava.rmi.server.codebase=file:C:pathtoclasses com.rm5248.rmiserver.RMIServerMain
- Run the RMIClient. Make sure that when setting the RMI server codebase, the path ends with a /, otherwise it will not work. Also ensure that client.policy is accessible by the application.
java -Djava.rmi.server.useCodebaseOnly=false -Djava.rmi.server.codebase=file:C:pathtoclasses -Djava.security.policy=client.policy com.rm5248.rmiclient.RMIClientMain
Everything should now come up and you should see a message in the server window. The client prints out the number of characters that it sent to the server.
Other Notes
If you improve this example in any way, feel free to send a pull request.
A Chat application using java remote method invocation
A third year college project ? 3️⃣
This is a project to build a client-server chat application using java RMI technologyThe directories included in this repo:
- Java-RMI-Chat: The eclipse project directory
- Client: All relevant code for the client chat GUI.
- Server: The code for the central server.
- Design: UML diagrams and wireframe sketch design
Features:
- The appplication follows a hub and spoke topology, with the server as the hub.
- Clients logon to the system with a username
- Clients can send a normal chat message(broadcast to all clients)
- Clients can send a private message to one or more clients
- Server maintains a user list, which is displayed in client GUI
- Online user list is updated on all clients when users join or leave the chat room
Instructions
- Start the server first (main method: ChatServer.java)
- Start a client (main method: ClientRMIGUI.java)
- Enter a unique username to join the chat