Week 9

Client & Server with java.rmi.*


When I started to make a concept about the implementation of my client server architecture I only knew that I had to use Java. So I had to discover its packages to get an idea how to do it with that language. To use java.rmi.* seemed to be the easiest way to do it.
Also the java.net package provides a programmer with the possibility to implement a client and a server. But its classes seemed much too complicate for an absolute novice that I am in the field of network.programming
In fact there has been much too less time to do all the tasks that had to be done for the application. So I was happy to have at leats for the connection module a very easy way to implement it.

Client & Server and their Remote Interface

Implementing a remote object with java.rmi packages means to implement a remote interface that has been extended from the java.rmi.Remote interface.
It is the definition of the protocoll used for connections to objects that implement this interface.

The interface of the first version of my client is shown in the table below. With it my client was able to receive some messages from a connected remote object.

remote interface
//define remote client interface

public interface MedNetRemoteC extends java.rmi.Remote
{ public void ServerMsg(String msg)
throws java.rmi.RemoteException;

The interface of the first version of my server is shown in the next table. With it the server was able to register a remote object to unregister a registered object and to receive some messages from a connected remote object.

remote interface
//define remote server interface

public interface MedNetRemoteS extends java.rmi.Remote
{ public boolean registerClient(MedNetRemoteC newClient)
throws java.rmi.RemoteException;

public boolean unregisterClient(MedNetRemoteC Client)
throws java.rmi.RemoteException;

public void messageout(String msg)
throws java.rmi.RemoteException;

These interfaces were implemented by the MedNetClient and the MedNetServer class.

In a later version of the client and server interfaces these interfaces became one, having only one method.

Remote interface /**
* This is an interface for invoking remote methods from a connected object.
* It is an interface especially for the Telemedicine project to enable
* the client or the server to comunicate with the respective counterpart
* by executing some Tasks on it.
public interface MedNetRemote extends java.rmi.Remote
{ public abstract void runTask(Task t)
throws java.rmi.RemoteException;

The Task to be executed is another interface, the implementations of which can be executed by the runTask function of every implementation of the MedNetRemote interface.

That doesn't actually mean that we have less source code. It only makes it much easier to extend the functionality of client or server. For that I have to add some Tasks only.

The Task interface needed for the function in MedNetRemote: import java.io.Serializable;

public interface Task extends Serializable
{ public abstract boolean runtask(); }

[startpage] [project part 1] [project part 2] [week 1] [week 2] [week 3] [week 4] [week 5] [week 6] [week 7] [week 8] [week 9] [week 10] [week 11] [References]

Because english is not the native language of the authors, we apologize for any inconvenience.

© 1998 by Matthias Kraft & Gesine Schröter;
EMail to: M.Kraft@fhtw-berlin.de & g.schroeter@fhtw-berlin.de
Last changed: Sunday, 08-Feb-2009 12:42:19 CET