Oop Iop
Oop Iop
Oop Iop
Email:[email protected]
Integrated Polytechnic Regional College
www.iprckarongi.rp.ac.rw
Year 2, Semester II
Academic year 2019/2020
28 April, 2020
1
Running RMI Program in NetBeans IDE .................................................................................................... 3
Introduction ........................................................................................................................................ 3
1.Create the remote interface.......................................................................................................... 3
2.Create the Implementation Class (Remote Object) ........................................................................ 3
3.Create, Define and Run Server application .................................................................................... 3
4.Create, Define and Run Client application ..................................................................................... 3
Implementation................................................................................................................................... 4
Step 1: Create A new Project Named rmi ......................................................................................... 4
Step 2: Create Java Interface............................................................................................................ 6
Press Right click on rmi, Select New and then Select Java Interface .............................................. 6
Codes........................................................................................................................................... 8
Step 3: Create Java Class: server ...................................................................................................... 9
Press Right click on rmi, Select New and then Select Java Class .................................................... 9
Codes......................................................................................................................................... 11
Step 4: Create Java Class: client...................................................................................................... 12
Codes......................................................................................................................................... 13
Testing .............................................................................................................................................. 14
Running the Server Program First................................................................................................... 14
Running the Client Program ........................................................................................................... 15
Note: ............................................................................................................................................. 15
Example: You tried to run Client Program without running the server program First, you will get
Error .......................................................................................................................................... 16
2
Running RMI Program in NetBeans IDE
Introduction
Can write an implementation class separately or can directly make the server program implement
this interface.
3
Implementation
Click Next
4
Click Finish
5
Step 2: Create Java Interface
Press Right click on rmi, Select New and then Select Java Interface
6
Click Finish
Then project Name is: adder.java
7
Codes
package rmi;
import java.rmi.*;
8
Step 3: Create Java Class: server
Press Right click on rmi, Select New and then Select Java Class
9
Click Finish
Then project Name is: server.java
10
Codes
package rmi;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
@Override
public int add(int n1, int n2) throws RemoteException {
return n1+n2;
}
public static void main(String args[]){
try{
Registry reg=LocateRegistry.createRegistry(9999);
reg.rebind("hi Server", new server());
System.out.println("Server is Ready") ;
}
catch(RemoteException e){
System.out.println(e) ;
}
}
}
11
Step 4: Create Java Class: client
Click Finish
Then project Name is: client.java
12
Codes
package rmi;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Scanner;
13
Testing
14
Running the Client Program
Note:
If the server program is not running the client program also not Running
Run the Server program First if the Server Program is ready then run the Client
Program
15
Example: You tried to run Client Program without running the server program First, you
will get Error
16