Package org.cojen.dirmi


package org.cojen.dirmi
Dirmi is a framework for supporting bidirectional remote method invocation. For launching a server, create an Environment, export a remote object, and start accepting connections. For connecting a client, create an Environment, connect to the server, and obtain the root object. Here is a very simple example, starting with the remote interface:
import org.cojen.dirmi.Remote;
import org.cojen.dirmi.RemoteException;

public interface HelloDirmi extends Remote {
    void greetings(String name) throws RemoteException;
}
The server-side implementation looks like this:
import java.net.ServerSocket;

import org.cojen.dirmi.Environment;

public class HelloDirmiServer implements HelloDirmi {
    public static void main(String[] args) throws Exception {
        Environment env = Environment.create();
        env.export("main", new HelloDirmiServer());
        env.acceptAll(new ServerSocket(1234));
    }

    @Override
    public void greetings(String name) {
        System.out.println("Hello " + name);
    }
}
And here is the client-side implementation:
import org.cojen.dirmi.Environment;
import org.cojen.dirmi.Session;

public class HelloDirmiClient {
    public static void main(String[] args) throws Exception {
        Environment env = Environment.create();
        String host = args[0];
        int port = 1234;
        Session<HelloDirmi> session = env.connect(HelloDirmi.class, "main", host, port);
        HelloDirmi client = session.root();

        client.greetings("Dirmi");

        env.close();
    }
}
See Also: