- A Lightweight Java Middleware
<< Example 2   Example 3b >>

Example 3a

shows how to distribute Agent and Listener over two processes:
the Agent is run HERE, the Listener THERE.

As to communication, everything works as in the previous example; the point of the example is that a proxy can be used as a parameter just like the "real" thing.


How to do it


package tw.net.ocs.example;

import tw.net.ocs.*;
import tw.net.ocs.proxy.*;

public class Example3a {
   public static void main(String[] args) {

      System.out.println("Running Example3a: Agent HERE, Listener THERE");

         // Create an OCSClient instance that
         "localhost",  // communicates with a server at this host
         23229,  // and this port,
         null,  // is unnamed, and
         true  // made the standard client to use by subsequently created proxies
         // Create an Agent and pass it a proxy Listener
         // (that delegates its invocations to a real Listener,
         // which it automatically creates on the remote server)
      Agent agent = new Agent(new TwNetOcsExampleListenerImpl());
         // ... and let the Agent act


To run the demo,
start a server in a separate shell:

java -cp ocs.jar tw.net.ocs.OCSServer -start -port 23229

and run Example3a:

java -cp ocs.jar;ocs-examples.jar tw.net.ocs.example.Example3a
Last modified Jun 8, 2006