SlideShare ist ein Scribd-Unternehmen logo
1 von 24
Remote Method Invocation
www.sunilos.com
www.raystec.com
www.SunilOS.com 2
Single Server App
Server
Payment
<<Service>>
Shop
<<JSP>>
Inventory
<<Service>>
www.SunilOS.com 3
Distributed Application
Client
Shop
<<JSP>>
Server 1
Payment
<<Service>>
Server - 2
Inventory
<<Service>>
www.SunilOS.com 4
Communication Protocol
Client
Shop
<<JSP>>
Server 1
Payment
<<Service>>
Server - 2
Inventory
<<Service>>
RMI
SOAP
(XML)
CORBA
www.SunilOS.com5
Java Remote Object Invocation (RMI)
 Java RMI allows the programmer to execute a method of
remote class using the same semantics as local method
call.
Local Machine (Client)
AddServer remoteObject;
int s;
…
s=remoteObject.sum(1,2);
System.out.println(s);
Remote Machine
(Server)
public int sum(int
a,int b) {
return a + b;
}
1,2
3
www.SunilOS.com 6
The General RMI Architecture
 The server must first bind its
name to the registry.
 The client looks up the
server name in the registry
to establish remote
references.
 The Stub serializes the
parameters to skeleton, the
skeleton invokes the remote
method and serializes the
result back to the stub.
www.SunilOS.com 7
The Stub and Skeleton
 A client invokes a remote method, the call is first forwarded to
stub.
 The stub is responsible for sending the remote call over to the
server-side skeleton.
 The stub opens a socket to the remote server, marshals the
object parameters and forwards the data stream to the skeleton.
 A skeleton contains a method that receives the remote calls,
unmarshals the parameters, and invokes the actual remote object
implementation.
Stub
RMI Client RMI Server
skeleton
return
call
www.SunilOS.com 8
Steps for Developing an RMI System
1. Define the remote interface.
2. Develop the remote object by implementing the remote
interface.
3. Develop the client program.
4. Compile the Java source files.
5. Generate the client stubs and server skeletons.
6. Start the RMI registry.
7. Start the remote server objects.
8. Run the client.
www.SunilOS.com 9
Class Hierarchy
Remote
<<interface>>
AddServerIntf
<<interface>>
+ sum(int a,int b):int
AddServerImpl
+ sum(int a,int b):int
+add(int a):int
extends
implements
UnicastRemoteObject
extends
RMIRegistry
<<index>>
Client
www.SunilOS.com 10
Step 1: Defining the Remote Interface
import java.rmi.*;
public interface AddServerIntf extends Remote
{
public int sum(int a,int b) throws
RemoteException;
}
www.SunilOS.com 11
Step 2: Defining the Remote Server
 The server is a simple unicast remote server. Server is created by
extending java.rmi.server.UnicastRemoteObject.
 The server uses the RMISecurityManager to protect its resources
while engaging in remote communication.
import java.rmi.*; import java.rmi.server.*;
import java.rmi.registry.*;
public class AddServerImpl extends UnicastRemoteObject implements
AddServerIntf {
AddServerImpl() throws RemoteException{
super();
}
….
www.SunilOS.com 12
Step 2: Defining the Remote Server ( Cont.)
// Remote method implementation
public int sum(int a,int b) throws RemoteException{
return a + b;
}
The server must bind its name to the registry, the client will look up the
server name.
Use java.rmi.Naming class to bind the server name to registry. In this
example the name of server is “ADD-SERVER”.
In the main method of your server object, the RMI security manager is
created and installed.
www.SunilOS.com 13
Step 2: Defining the Remote Server
 Main method to start Server
public static void main(String args[]) throws Exception{
//set the security manager
System.setSecurityManager(new RMISecurityManager());
//create a local instance of the server object
AddServerImpl serverObj= new AddServerImpl();
//Bind server instance with RMI Registry
Naming.rebind("ADD-SERVER" , serverObj);
System.out.println("Server is started.....");
}
www.SunilOS.com 14
Step 3: Developing the Client program
 Client will look up the name of server in the registry using
java.rmi.Naming class.
 The server name is specified as URL:
o rmi://host:port/name
 Default RMI port is 1099.
 The name specified in the URL must exactly match the name that
the server has bound to the registry. In this example, the name of
server is “ADD-SERVER”.
 The remote method invocation is programmed using the remote
interface name (remoteObject) as prefix and the remote method
name (sum) as suffix.
www.SunilOS.com 15
Step 3: Developing the client program (Cont.)
public class SampleClient{
public static void main(String[] args){
// set the security manager for the client
System.setSecurityManager(new RMISecurityManager());
//get the remote object from the registry
try {
String url = “rmi://localhost:1099/ADD-SERVER”;
AddServerIntf remoteObject =(AddServerIntf)Naming.lookup(url);
System.out.println(" SUM = " + remoteObject.sum(1,2) );
}catch (RemoteException exc) {
System.out.println("Error in lookup: " + exc.toString()); }
catch (java.net.MalformedURLException exc) {
System.out.println("Malformed URL: " + exc.toString()); }
catch (java.rmi.NotBoundException exc) {
System.out.println("NotBound: " + exc.toString());
}
}
www.SunilOS.com 16
Step 4 : Compiling Classes
Assume the program is in c:rmi
o c:rmi> set CLASSPATH=”c:/rmi”
o c:rmi> javac AddServerIntf.java
o c:rmi> javac AddServerImpl.java
o c:rmi> javac SampleClient.java
www.SunilOS.com 17
Step 5: Generating stubs and skeletons
 The RMI system provides an RMI compiler (rmic) that
takes your RMI interface and class and generates stub
and skeleton.
 Assuming that classes are stored in c:/rmi folder and
run following commands from command prompt:
o c:rmi> set CLASSPATH=”c:/rmi”
o c:rmi> javac AddServerIntf.java
o c:rmi> javac AddServerImpl.java
o c:rmi> rmic AddServerImpl
www.SunilOS.com 18
Step 6: Starting the RMI registry
 The RMI Server objects are bound with the RMI Registry
and registry is started by calling command:
o rmiregistry
 By default port #1099 is used by RMI Registry. You can
also bind registry to a different port number by indicating
the port number next to command as:
o rmiregistry <new port>
 c:rmi>rmiregistry 1099
www.SunilOS.com 19
Steps 7: Starting Server and Client
 First Registry is started then Server will be started and bound to
Registry by a unique name.
 A security policy will be set when server is started. Granted
permissions are declared in a policy file. It is a text file. Policy file is
applied by –D command option:
o –Djava.security.policy=policy.all
 Open a command prompt and start server by:
o c:rmi> java –Djava.security.policy=policy.all AddServerImpl
 Open another command prompt and run client:
o c:rmi> java –Djava.security.policy=policy.all SampleClient
www.SunilOS.com 20
Java Policy File
The Java application must first obtain information
regarding its privileges. It can obtain the security
policy through a policy file.
In our example, we will allow Java code to have
all permissions. Policy file contents will be:
grant {
permission java.security.AllPermission;
};
Specific Permissions
grant {
permission java.io.filePermission “/tmp/*”, “read”, “write”;
permission java.net.SocketPermission “www.sunrays..co.in :
999”,”connect”;
permission java.net.SocketPermission “*:1024-65535”,”connect,request”;
permission java.net.SocketPermission “*:80”,”connect”;
};
Allows classes to read/write any file under the “/tmp” directory and its
subdirectories.
Allows classes to establish a network connection with the host
“www.SunilOS.com” at port 999.
Allows classes to connect to or accept connections on unprivileged
ports greater than 1024, on any host.
Allows all classes to connect to the HTTP port 80 on any host.
www.SunilOS.com 21
www.SunilOS.com 22
Run it!
 Open Command Prompt 1
 >rmiregistry
 Open Command Prompt 2
 >java -Djava.security.policy=policy.all AddServer
 Open Command Prompt 3
 >java -Djava.security.policy=policy.all AddClient
Disclaimer
This is an educational presentation to enhance the
skill of computer science students.
This presentation is available for free to computer
science students.
Some internet images from different URLs are
used in this presentation to simplify technical
examples and correlate examples with the real
world.
We are grateful to owners of these URLs and
pictures.
www.SunilOS.com 23
Thank You!
www.SunilOS.com 24
www.SunilOS.com

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Interface
InterfaceInterface
Interface
 
Servlets
ServletsServlets
Servlets
 
Remote Method Invocation (RMI)
Remote Method Invocation (RMI)Remote Method Invocation (RMI)
Remote Method Invocation (RMI)
 
Servlet.ppt
Servlet.pptServlet.ppt
Servlet.ppt
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File Handling
 
Threads concept in java
Threads concept in javaThreads concept in java
Threads concept in java
 
Java socket programming
Java socket programmingJava socket programming
Java socket programming
 
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)
 
Real-Time Scheduling Algorithms
Real-Time Scheduling AlgorithmsReal-Time Scheduling Algorithms
Real-Time Scheduling Algorithms
 
Jsp/Servlet
Jsp/ServletJsp/Servlet
Jsp/Servlet
 
Java rmi
Java rmiJava rmi
Java rmi
 
Parallel processing
Parallel processingParallel processing
Parallel processing
 
Spring AOP
Spring AOPSpring AOP
Spring AOP
 
Interface in java
Interface in javaInterface in java
Interface in java
 
URL Class in JAVA
URL Class in JAVAURL Class in JAVA
URL Class in JAVA
 
Chap 12 tcp
Chap 12 tcpChap 12 tcp
Chap 12 tcp
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Threads in JAVA
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 
Java And Multithreading
Java And MultithreadingJava And Multithreading
Java And Multithreading
 
Remote Method Invocation (Java RMI)
Remote Method Invocation (Java RMI)Remote Method Invocation (Java RMI)
Remote Method Invocation (Java RMI)
 

Ähnlich wie Java RMI (20)

Distributed Objects and JAVA
Distributed Objects and JAVADistributed Objects and JAVA
Distributed Objects and JAVA
 
Rmi
RmiRmi
Rmi
 
Rmi
RmiRmi
Rmi
 
Java rmi example program with code
Java rmi example program with codeJava rmi example program with code
Java rmi example program with code
 
Java remote method invocation
Java remote method invocationJava remote method invocation
Java remote method invocation
 
Remote Method Invocation in JAVA
Remote Method Invocation in JAVARemote Method Invocation in JAVA
Remote Method Invocation in JAVA
 
Rmi
RmiRmi
Rmi
 
Remote method invocatiom
Remote method invocatiomRemote method invocatiom
Remote method invocatiom
 
Java rmi
Java rmiJava rmi
Java rmi
 
Rmi ppt
Rmi pptRmi ppt
Rmi ppt
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
 
ADB Lab Manual.docx
ADB Lab Manual.docxADB Lab Manual.docx
ADB Lab Manual.docx
 
17rmi
17rmi17rmi
17rmi
 
Android workshop
Android workshopAndroid workshop
Android workshop
 
Call Back
Call BackCall Back
Call Back
 
Call Back
Call BackCall Back
Call Back
 
Call Back
Call BackCall Back
Call Back
 
Call Back
Call BackCall Back
Call Back
 
Module 1 Introduction
Module 1   IntroductionModule 1   Introduction
Module 1 Introduction
 
Rmi3
Rmi3Rmi3
Rmi3
 

Mehr von Sunil OS

Mehr von Sunil OS (20)

Threads V4
Threads  V4Threads  V4
Threads V4
 
Java IO Streams V4
Java IO Streams V4Java IO Streams V4
Java IO Streams V4
 
OOP V3.1
OOP V3.1OOP V3.1
OOP V3.1
 
Java Basics V3
Java Basics V3Java Basics V3
Java Basics V3
 
DJango
DJangoDJango
DJango
 
PDBC
PDBCPDBC
PDBC
 
OOP v3
OOP v3OOP v3
OOP v3
 
Threads v3
Threads v3Threads v3
Threads v3
 
Exception Handling v3
Exception Handling v3Exception Handling v3
Exception Handling v3
 
Collection v3
Collection v3Collection v3
Collection v3
 
Java 8 - CJ
Java 8 - CJJava 8 - CJ
Java 8 - CJ
 
Machine learning ( Part 3 )
Machine learning ( Part 3 )Machine learning ( Part 3 )
Machine learning ( Part 3 )
 
Machine learning ( Part 2 )
Machine learning ( Part 2 )Machine learning ( Part 2 )
Machine learning ( Part 2 )
 
Machine learning ( Part 1 )
Machine learning ( Part 1 )Machine learning ( Part 1 )
Machine learning ( Part 1 )
 
Python Pandas
Python PandasPython Pandas
Python Pandas
 
Python part2 v1
Python part2 v1Python part2 v1
Python part2 v1
 
Angular 8
Angular 8 Angular 8
Angular 8
 
Python Part 1
Python Part 1Python Part 1
Python Part 1
 
C# Variables and Operators
C# Variables and OperatorsC# Variables and Operators
C# Variables and Operators
 
C# Basics
C# BasicsC# Basics
C# Basics
 

Kürzlich hochgeladen

ppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyesppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyes
ashishpaul799
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 

Kürzlich hochgeladen (20)

size separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticssize separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceutics
 
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
 
....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdf....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdf
 
MichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdfMichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdf
 
Behavioral-sciences-dr-mowadat rana (1).pdf
Behavioral-sciences-dr-mowadat rana (1).pdfBehavioral-sciences-dr-mowadat rana (1).pdf
Behavioral-sciences-dr-mowadat rana (1).pdf
 
An Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptxAn Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptx
 
Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17
 
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
 
Word Stress rules esl .pptx
Word Stress rules esl               .pptxWord Stress rules esl               .pptx
Word Stress rules esl .pptx
 
ppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyesppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyes
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17
 
Open Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPointOpen Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPoint
 
The Ultimate Guide to Social Media Marketing in 2024.pdf
The Ultimate Guide to Social Media Marketing in 2024.pdfThe Ultimate Guide to Social Media Marketing in 2024.pdf
The Ultimate Guide to Social Media Marketing in 2024.pdf
 
Navigating the Misinformation Minefield: The Role of Higher Education in the ...
Navigating the Misinformation Minefield: The Role of Higher Education in the ...Navigating the Misinformation Minefield: The Role of Higher Education in the ...
Navigating the Misinformation Minefield: The Role of Higher Education in the ...
 
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
 
How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17
 
The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resources
 
The Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. HenryThe Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. Henry
 
philosophy and it's principles based on the life
philosophy and it's principles based on the lifephilosophy and it's principles based on the life
philosophy and it's principles based on the life
 

Java RMI

  • 2. www.SunilOS.com 2 Single Server App Server Payment <<Service>> Shop <<JSP>> Inventory <<Service>>
  • 3. www.SunilOS.com 3 Distributed Application Client Shop <<JSP>> Server 1 Payment <<Service>> Server - 2 Inventory <<Service>>
  • 4. www.SunilOS.com 4 Communication Protocol Client Shop <<JSP>> Server 1 Payment <<Service>> Server - 2 Inventory <<Service>> RMI SOAP (XML) CORBA
  • 5. www.SunilOS.com5 Java Remote Object Invocation (RMI)  Java RMI allows the programmer to execute a method of remote class using the same semantics as local method call. Local Machine (Client) AddServer remoteObject; int s; … s=remoteObject.sum(1,2); System.out.println(s); Remote Machine (Server) public int sum(int a,int b) { return a + b; } 1,2 3
  • 6. www.SunilOS.com 6 The General RMI Architecture  The server must first bind its name to the registry.  The client looks up the server name in the registry to establish remote references.  The Stub serializes the parameters to skeleton, the skeleton invokes the remote method and serializes the result back to the stub.
  • 7. www.SunilOS.com 7 The Stub and Skeleton  A client invokes a remote method, the call is first forwarded to stub.  The stub is responsible for sending the remote call over to the server-side skeleton.  The stub opens a socket to the remote server, marshals the object parameters and forwards the data stream to the skeleton.  A skeleton contains a method that receives the remote calls, unmarshals the parameters, and invokes the actual remote object implementation. Stub RMI Client RMI Server skeleton return call
  • 8. www.SunilOS.com 8 Steps for Developing an RMI System 1. Define the remote interface. 2. Develop the remote object by implementing the remote interface. 3. Develop the client program. 4. Compile the Java source files. 5. Generate the client stubs and server skeletons. 6. Start the RMI registry. 7. Start the remote server objects. 8. Run the client.
  • 9. www.SunilOS.com 9 Class Hierarchy Remote <<interface>> AddServerIntf <<interface>> + sum(int a,int b):int AddServerImpl + sum(int a,int b):int +add(int a):int extends implements UnicastRemoteObject extends RMIRegistry <<index>> Client
  • 10. www.SunilOS.com 10 Step 1: Defining the Remote Interface import java.rmi.*; public interface AddServerIntf extends Remote { public int sum(int a,int b) throws RemoteException; }
  • 11. www.SunilOS.com 11 Step 2: Defining the Remote Server  The server is a simple unicast remote server. Server is created by extending java.rmi.server.UnicastRemoteObject.  The server uses the RMISecurityManager to protect its resources while engaging in remote communication. import java.rmi.*; import java.rmi.server.*; import java.rmi.registry.*; public class AddServerImpl extends UnicastRemoteObject implements AddServerIntf { AddServerImpl() throws RemoteException{ super(); } ….
  • 12. www.SunilOS.com 12 Step 2: Defining the Remote Server ( Cont.) // Remote method implementation public int sum(int a,int b) throws RemoteException{ return a + b; } The server must bind its name to the registry, the client will look up the server name. Use java.rmi.Naming class to bind the server name to registry. In this example the name of server is “ADD-SERVER”. In the main method of your server object, the RMI security manager is created and installed.
  • 13. www.SunilOS.com 13 Step 2: Defining the Remote Server  Main method to start Server public static void main(String args[]) throws Exception{ //set the security manager System.setSecurityManager(new RMISecurityManager()); //create a local instance of the server object AddServerImpl serverObj= new AddServerImpl(); //Bind server instance with RMI Registry Naming.rebind("ADD-SERVER" , serverObj); System.out.println("Server is started....."); }
  • 14. www.SunilOS.com 14 Step 3: Developing the Client program  Client will look up the name of server in the registry using java.rmi.Naming class.  The server name is specified as URL: o rmi://host:port/name  Default RMI port is 1099.  The name specified in the URL must exactly match the name that the server has bound to the registry. In this example, the name of server is “ADD-SERVER”.  The remote method invocation is programmed using the remote interface name (remoteObject) as prefix and the remote method name (sum) as suffix.
  • 15. www.SunilOS.com 15 Step 3: Developing the client program (Cont.) public class SampleClient{ public static void main(String[] args){ // set the security manager for the client System.setSecurityManager(new RMISecurityManager()); //get the remote object from the registry try { String url = “rmi://localhost:1099/ADD-SERVER”; AddServerIntf remoteObject =(AddServerIntf)Naming.lookup(url); System.out.println(" SUM = " + remoteObject.sum(1,2) ); }catch (RemoteException exc) { System.out.println("Error in lookup: " + exc.toString()); } catch (java.net.MalformedURLException exc) { System.out.println("Malformed URL: " + exc.toString()); } catch (java.rmi.NotBoundException exc) { System.out.println("NotBound: " + exc.toString()); } }
  • 16. www.SunilOS.com 16 Step 4 : Compiling Classes Assume the program is in c:rmi o c:rmi> set CLASSPATH=”c:/rmi” o c:rmi> javac AddServerIntf.java o c:rmi> javac AddServerImpl.java o c:rmi> javac SampleClient.java
  • 17. www.SunilOS.com 17 Step 5: Generating stubs and skeletons  The RMI system provides an RMI compiler (rmic) that takes your RMI interface and class and generates stub and skeleton.  Assuming that classes are stored in c:/rmi folder and run following commands from command prompt: o c:rmi> set CLASSPATH=”c:/rmi” o c:rmi> javac AddServerIntf.java o c:rmi> javac AddServerImpl.java o c:rmi> rmic AddServerImpl
  • 18. www.SunilOS.com 18 Step 6: Starting the RMI registry  The RMI Server objects are bound with the RMI Registry and registry is started by calling command: o rmiregistry  By default port #1099 is used by RMI Registry. You can also bind registry to a different port number by indicating the port number next to command as: o rmiregistry <new port>  c:rmi>rmiregistry 1099
  • 19. www.SunilOS.com 19 Steps 7: Starting Server and Client  First Registry is started then Server will be started and bound to Registry by a unique name.  A security policy will be set when server is started. Granted permissions are declared in a policy file. It is a text file. Policy file is applied by –D command option: o –Djava.security.policy=policy.all  Open a command prompt and start server by: o c:rmi> java –Djava.security.policy=policy.all AddServerImpl  Open another command prompt and run client: o c:rmi> java –Djava.security.policy=policy.all SampleClient
  • 20. www.SunilOS.com 20 Java Policy File The Java application must first obtain information regarding its privileges. It can obtain the security policy through a policy file. In our example, we will allow Java code to have all permissions. Policy file contents will be: grant { permission java.security.AllPermission; };
  • 21. Specific Permissions grant { permission java.io.filePermission “/tmp/*”, “read”, “write”; permission java.net.SocketPermission “www.sunrays..co.in : 999”,”connect”; permission java.net.SocketPermission “*:1024-65535”,”connect,request”; permission java.net.SocketPermission “*:80”,”connect”; }; Allows classes to read/write any file under the “/tmp” directory and its subdirectories. Allows classes to establish a network connection with the host “www.SunilOS.com” at port 999. Allows classes to connect to or accept connections on unprivileged ports greater than 1024, on any host. Allows all classes to connect to the HTTP port 80 on any host. www.SunilOS.com 21
  • 22. www.SunilOS.com 22 Run it!  Open Command Prompt 1  >rmiregistry  Open Command Prompt 2  >java -Djava.security.policy=policy.all AddServer  Open Command Prompt 3  >java -Djava.security.policy=policy.all AddClient
  • 23. Disclaimer This is an educational presentation to enhance the skill of computer science students. This presentation is available for free to computer science students. Some internet images from different URLs are used in this presentation to simplify technical examples and correlate examples with the real world. We are grateful to owners of these URLs and pictures. www.SunilOS.com 23