Warning: Parameter 2 to qtranxf_postsFilter() expected to be a reference, value given in /home/.sites/609/site1266/web/blackbams-blog/wp-includes/class-wp-hook.php on line 286 Warning: count(): Parameter must be an array or an object that implements Countable in /home/.sites/609/site1266/web/blackbams-blog/wp-includes/post-template.php on line 284 Java RMI five Minutes tutorial • networking remote rmi Tutorial • Blackbams Blog
23. January 2013
von Blackbam
This ultra short tutorial is just a summary of how Java RMI (remote method invocation) works. For explanation please check one of the other tutorials which you will find easily easily your favorite search engine.

1. Write RMI-Server Interface

  • extends package java.rmi.Remote
  • provide all methods to be called remotely
  • each methods must through a remote exception
import java.rmi.*;
public interface ServerInterface extends Remote {
     public void method1() throws RemoteException;
     public int method2() throws RemoteException;
     // ...

2. Write Server Class

  • implements RMI-Server Interface
  • extends UnicastRemoteObject (at least for simple RMI)
  • Constructor throws java.rmi.RemoteException
  • must be registered at local registry
import java.rmi.*;
import java.net.MalformedURLExcpetion;
import java.rmi.registry.*;
import java.rmi.server.UnicastRemoteObject;
public class MyServer extends UnicastRemoteObject implements ServerInterface {
  MyServer() throws RemoteException {
  public static void main(String[] args) {

    try {
    } catch (RemoteException ex) {
    try {
      Naming.rebind("MyServer", new MyServer());
    } catch (MalformedURLException ex) {
    catch (RemoteException ex) {
  // ...

3. Write a client

  • get remote reference
  • call remote methods
  • be careful with rmi-specific problems (a more detailed tutorial will explain to you)
// any class, ...
// url expects String in url format (e.g. for local testing)
try {
      ServerInterface server = (ServerInterface) Naming.lookup(url);
      int calculated_by_server = server.method2();
      // ...
} catch (Exception ex) {

  API reference:   Further reading: http://docs.oracle.com/javase/tutorial/rmi/index.html

Dieser Eintrag wurde am 23. January 2013 um 10:10 in der Kategorie Java, Programming veröffentlicht. You can book the comments for this article RSS 2.0. Feedback, discussion, commendation and critics are welcome: Write a comment or trackback.

Tags: , , ,

Warning: Use of undefined constant Ext_related_links - assumed 'Ext_related_links' (this will throw an Error in a future version of PHP) in /home/.sites/609/site1266/web/blackbams-blog/wp-content/themes/SilentWoodsByBlackbam/single.php on line 75

No comments yet

Kommentare abonnieren (RSS) or URL Trackback

Leave a comment: