Java Reference
In-Depth Information
Notice that we have used the same name, Cor19 , that the servant was
bound with and that we have narrowed to a Cor19Example interface using the
Cor19ExampleHelper class. Now we are ready to call methods on the servant:
cor19.method1 ("Hello");
int result = cor19.add (4, 9);
System.err.println ("add(4,9) returns " + result);
We must, of course, close the try/catch block and handle any errors. For this
simple example, we just dump the stack trace:
} catch (Exception e) {
e.printStackTrace (System.err);
}
} // main
19.6 Running the example
To test this example, we need to start the name service, start the server, and run the
client. For CORBA, the name service is started with orbd ,which needs to know
the port number and host. For running client and server on the same machine,
the host can be left off, allowing it to default to localhost. So we start orbd as
follows:
start orbd -ORBInitialHost localhost -ORBInitialPort 3001
To start the server, we run the javatech.cor19.server.impl.Cor19-
Server class. Notice that we pass in the ORBInitialPort property via the
system properties object (i.e. the -Dname = value syntax) rather than as a com-
mand line parameter. Either method may be used, since the server was coded to
accept either command line arguments or system properties:
java -classpath build/classes
-Dorg.omg.CORBA.ORBInitialPort=3001
javatech.cor19.server.impl.Cor19Server
(Here, and in later examples, we split command lines to fit within the page
margins.) We run the client, in another command shell window, similarly. But
notice that the client code above does not pass the system properties object to
ORB.init() . Therefore we must use the command-line arguments feature to
specify the port number on which to lookup the name server:
java -classpath build/classes javatech.cor19.client.Client
-ORBInitialPort 3001
The output should be
add(4,9) returns 32
Search WWH ::




Custom Search