A comprehensive Java Remote Method Invocation (RMI) application that demonstrates client-server communication and remote object invocation.
This project implements a classic RMI example where a server hosts multiple product objects and clients can remotely access these products to retrieve their information (name, description, and price) over the network.
Client Side
├── Client.java # Main client application
└── Product.java # Remote interface for product operations
Server Side
├── Server.java # Main server application
├── Product.java # Remote interface (same as client)
├── ProductImpl.java # Implementation of Product interface
└── ProductImpl.class # Compiled implementation
Entry Point
└── Main.java # Simple hello world example (not part of RMI system)
-
Remote Interface (Product.java): Defines the contract for remote operations
getName()- Returns product namegetDescription()- Returns product descriptiongetPrice()- Returns product price
-
Implementation (ProductImpl.java): Implements the remote interface
- Contains product data (name, description, price)
- Provides actual implementations of remote methods
-
Server (Server.java): RMI Server Application
- Creates multiple product instances
- Exports objects for remote access
- Registers objects in RMI registry
- Hosts 4 different products (Product1-4)
-
Client (Client.java): RMI Client Application
- Connects to RMI registry
- Looks up remote objects by name
- Invokes remote methods to get product information
- Java Development Kit (JDK) 8 or higher
- Java Runtime Environment (JRE) 8 or higher
- Integrated Development Environment (IDE) like IntelliJ IDEA, Eclipse, or VS Code
The application is configured for localhost operation:
- Server IP: 127.0.0.1 (localhost)
- RMI Registry Port: 1099
- Hostname: 127.0.0.1
# Compile all Java files
javac -d . src/**/*.java# Start RMI registry (in background)
rmiregistry &# Run the server application
java -cp . server.Server# Run the client application
java -cp . client.Client- Open the project in your IDE
- Run Server.java first (right-click → Run)
- Run Client.java second (right-click → Run)
- Server starts successfully
- Creates 4 product instances
- Exports and registers them in RMI registry
- No console output when running successfully
Product Name: Product 1
Product Description: Description of Product 1
Product Price: 10.99
-
Server Initialization:
- Creates
ProductImplinstances with sample data - Exports objects using
UnicastRemoteObject.exportObject() - Registers objects in RMI registry with names "Product1" to "Product4"
- Sets hostname property for network access
- Creates
-
Client Operation:
- Locates RMI registry on localhost:1099
- Looks up remote objects by registry names
- Casts retrieved objects to
Productinterface - Invokes remote methods to get product information
- Registry: Uses default RMI registry port 1099
- Hostname: Configured as 127.0.0.1 for local testing
- Protocol: Uses Java RMI protocol (JRMP)
RMI/
├── README.md # This documentation
├── RMI.iml # IntelliJ IDEA module configuration
└── src/
├── Main.java # Hello world example (not RMI-related)
├── client/
│ ├── Client.java # RMI Client application
│ └── Product.java # Remote interface
└── server/
├── Product.java # Remote interface (same as client)
├── ProductImpl.java # Implementation of Product interface
└── Server.java # RMI Server application
-
RMI Registry Not Running:
java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is: java.net.ConnectException: Connection refusedSolution: Start
rmiregistrybefore running the server -
ClassNotFoundException:
java.lang.ClassNotFoundException: client.ProductSolution: Ensure proper classpath with
-cp .or use IDE's run configuration -
AlreadyBoundException:
java.rmi.server.AlreadyBoundException: Product1Solution: Restart the server to clear registry or use different binding names
-
Security Manager Issues: If using security policies, ensure proper permissions are granted
- Check Registry: Verify that objects are properly registered
- Network: Ensure no firewall blocks port 1099
- Classpath: Verify all compiled classes are accessible
- Server Order: Always start server before client
- Java RMI API (built-in with JDK)
- No external dependencies required
- The
Main.javafile contains a simple hello world example and is not part of the RMI system - The project uses separate packages for client and server code organization
- All remote methods throw
RemoteExceptionas required by RMI specification - The implementation uses
UnicastRemoteObjectfor remote object export
This project serves as a practical demonstration of:
- Remote Method Invocation concepts
- Client-server architecture
- Remote object lifecycle management
- Network programming in Java
- Interface-based remote design patterns
Created for Advanced Programming Course - Semester 5
University of Ruhuna