Location: Information Technology

Discussion: RMI-ProgramReported This is a featured thread

Showing 1 post

Posted Anonymously
RMI-Program
Oct 16 2007, 12:49 PM EDT | Post edited: Oct 16 2007, 12:49 PM EDT
//RMI Interface

import java.rmi.*;
public interface Hello extends java.rmi.Remote
{
public void Hi() throws java.rmi.RemoteException;
}

Save this file as Hello.java and Compile it using
javac.

//Implementation File

import java.rmi.*;

class Implementation extends
java.rmi.server.UnicastRemoteObject implements Hello
{
Implementation() throws java.rmi.RemoteException
{
super();
}
public void Hi() throws java.rmi.RemoteException
{
System.out.println("HELLO!!!");
}
}

Save file as Implementation.java and compile it.

//Server Side Program

import java.rmi.Naming;
class Server
{
public static void main(String args[])
{
try
{
Implementation i = new Implementation();

Naming.rebind("rmi://localhost:1099/HelloService",i);
}
catch(Exception e)
{
System.out.println("Exception at server!!"+e);
}
}
}

Save file as Server.java and compile.

//Client Side Implementation

import java.rmi.Naming;
class Client
{
public static void main(String args[])
{
try
{
Hello
p=(Hello)Naming.lookup("rmi://localhost/HelloService");
p.Hi();
}
catch(Exception e)
{
System.out.println("Exception at client");
}
}
}

Save File as Client.java and compile.

Execution:
1.Open command
2. rmic Implementation
3. rmiRegistry
4.Open new command prompt
4.1 java Server
5.Open new Command prompt
5.1 java Client
6.Stop.
1  out of 1 found this valuable. Do you?    
Keyword tags: None (edit keyword tags)

Be the first to reply.