
shows how to create and run an Agent and a Listener on a remote server with the help of a local proxy Agent.
Compare the code below with that of Example 1 to see how little it takes to turn a local application into a client/server application with OCSelot.

package tw.net.ocs.example;
import tw.net.ocs.*;
import tw.net.ocs.proxy.*;
public class Example2 {
public static void main(String[] args) {
System.out.println("Running Example2: Agent+Listener THERE");
// Create an OCSClient instance that
OCSClient.createInstance(
"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 a proxy Agent and pass it a real Listener
// (The proxy Agent constructor allocates a real Agent on the
// remote server THERE and passes the Listener on to that.)
Agent agent = new TwNetOcsExampleAgent(new ListenerImpl());
// ... and let the Agent THERE act
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 Example2:
java -cp ocs.jar;ocs-examples.jar tw.net.ocs.example.Example2