Remote Method Invocation: Working of An RMI Application
Remote Method Invocation: Working of An RMI Application
Which allows a Java object that executes on one machine to invoke a method of a
Java object that executes on another Machine. In this way RMI supports Distributed
applications.
Java C++
* Server side
* Client Side.
Server side
Method definitions.
2. A Class file that implements the interface. This class extends the
UnicastRemoteObject class.
3. The third file creates the object of the class and binds the object in RMI
Registry.
Client
A file that creates a class that access the remote object through rmi registry.
jdk\bin> rmiregistry
Stub/Skeleton Layer -> The stub acts as a representative of a server on the client
side and skeleton acts as a representative of a client on the server side.
Stub Class
Skeleton Class
The remote reference layer acts as a layer of abstraction between the stub
and skeleton classes and the communication protocols that are handled by the transport
layer.
Transport layer
Client
Application
Server Appln
Application Layer
Stub/ Skeleto
Stub Skeleton n
Layer
Transport Layer
Programs
SimpleIntf.java
import java.rmi.*;
SimpleImpl.java
import java.rmi.*;
import java.rmi.server.*;
Server.java
import java.rmi.*;
class Server
{
public static void main(String args[]) throws Exception
{
SimpleImpl s1 = new SimpleImpl();
System.out.println("Server Initializing....");
Naming.rebind("sys1",s1);
System.out.println("Server Registered...");
}
}
Client.java
import java.rmi.*;
import java.rmi.server.*;
class Client
{
public static void main(String args[]) throws Exception
{
String url = "rmi://system6/sys1";
SimpleIntf intf1 = (SimpleIntf) Naming.lookup(url);
int c = intf1.add(10,20);
int d = intf1.sub(40,30);
System.out.println("c = " + c);
System.out.println("d = " + d);
}
}
javac SimpleIntf.java
javac SimpleImpl.java
rmic SimpleImpl
javac Server.java
javac Client.java
>rmiregistry
>java Server
ChatIntf.java
import java.rmi.*;
ChatImpl.java
import java.rmi.*;
import java.rmi.server.*;
ChatServer.java
import java.rmi.*;
import java.rmi.server.*;
ChatClient.java
import java.rmi.*;
import java.rmi.server.*;
import java.applet.*;
import java.awt.event.*;
import java.awt.*;
Naming.lookup("rmi://system16/chat");
}
catch(Exception e)
{
System.out.println("Lookup Error");
}
l1 = new Label("Username : ");
l2 = new Label("Message : ");
tf = new TextField(20);
tf1 = new TextField(30);
ta = new TextArea();
add(l1);
add(tf);
add(l2);
add(tf1);
add(ta);
tf.addActionListener(this);
tf1.addActionListener(this);
DBIntf.java
import java.rmi.*;
import java.io.*;
import java.sql.*;
DBImpl.java
import java.rmi.*;
import java.rmi.server.*;
import java.sql.*;
DBClient.java
import java.rmi.*;
import java.rmi.server.*;
import java.sql.*;