top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Create RMI Step

0 votes
323 views

Step I

Create RemoteInterface.java

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

Step II

RemoteClass.java
import java.rmi.server.*;
import java.rmi.*;
class RemoteClass extends UnicastRemoteObject implements RemoteInterface{
    public RemoteClass()throws RemoteException {
        
    }
    public void remoteMethod()throws RemoteException{
        System.out.println("a client called...");
    }    
}

Step III

RemoteServer.java
import java.rmi.registry.*;
import java.rmi.*;
class RemoteServer{
    public static void main(String arga[]){
        System.setProperty("java.rmi.server.hostname","192.168.1.200");
        try{
            Registry remoteRegistry =LocateRegistry.createRegistry(5050);
            System.out.println("Server is starting..");
            remoteRegistry.rebind("RemoteServer",new RemoteClass());
        }catch(RemoteException ex){
            System.out.println(ex);
        }
    }
}

Step IV

RemoteClient.java
import java.rmi.*;
import java.rmi.server.*;
import java.net.*;
class RemoteClient{
    public static void main(String args[]){
        try{
            RemoteInterface remoteObject=(RemoteInterface)Naming.lookup("rmi://192.168.1.200:5050/RemoteServer");
            remoteObject.remoteMethod();
        }catch(RemoteException ex){
            
        }catch(MalformedURLException ex){
        
        }catch(NotBoundException ex){
            
        }
    }
}

Step V

Call a Method

First Of Server , Second Of Client and again Server To Run a program

 

 

posted Nov 16, 2017 by Madu Hansi

  Promote This Article
Facebook Share Button Twitter Share Button LinkedIn Share Button


Related Articles

Fermi is a Server-to-Client remote method invocation (RMI) framework. (The name “Fermi” loosely stands for Flip Ended Remote Method Invocation.) It enables remote invocation of client-side JavaScript code from server-side Java. It is not a Java wrapper around server-side JavaScript: the Java code runs under a Web Servlet container such as Tomcat, and the JavaScript runs in a Web browser, such as Firefox.

There are two primary motivations behind this “flip-ended” RMI. One is to enable an elegant way to push data to the browser via calling a remote fnction insead of sending a message. But perpahs even more importantly, it enables the server side Java to directly consume JavaScript APIs from third parties, such as the Google Maps or Google Charts APIs.

The Fermi framework is build on top of WebSockets API, which provides the low-level full-duplex message transport between the remote JavaScript client and the Java server. Just like the WebSockets, it has a Java API and a JavaScript API. But unlike the WebSockets, it exposes a higher-level abstraction whereby the Java domain can directly call JavaScript functions in the remote browser, pass arguments to them, and receive results of their computation.

Example

Below is the minimal code that will get things off the ground.

Server:

FermiEndpoint ep = FermiContainer.getInstance().newEndpoint("/example");
FermiSession session = ep.getSessionBlocking(request.getSession());
session.invoke(new Method("myJsFunction"));

Client:

var session = new fermi.Session(‘/example’); 
function myJsFunction() {
    // do something
}

The code above hardly needs explaining. In the Server section, we create a FermiEndpoint, i.e. the communication mechanism between remote browsers and this server. On the second line we acquire the connection to the particular browser, represented by its HTTP Session. And, finally, we invoke a JavaScript method called myJavaScriptFunction.

For this to work, on the JavaScript side of this connection, the client must create the client’s side of the session by instantiating the fermi.Session object, and define the function myJavaScriptFunction. In actuality, things can get much more complex.

The Fermi framework supports
1. Both asynchronous and blocking session acquisition.
2. Remote method parameters.
3. Asynchronous and blocking method invocation.
4. Result object inspection unmashalling.
5. Support for (un-)marshalling of many basic data types.
6. All asynchronous operations are exposed via the java.util.concurrent.Future mechanism.

Please check it out.
https://github.com/iurisman/FERMI

Apache 2.0 license.

READ MORE
...