Running the Hello World Applet
If all goes well, the applet appears below:
Building and Running Hello World Despite its simple design, the Hello World program lets you learn and experiment with all the tasks required to develop almost any CORBA program that uses static invocation. To run this client-server application on your development machine: When running this example, remember that the default port number is 900. When using Solaris software, you must become root to start a process on a port under 1024. For this reason, we recommend that you use a port number greater than or equal to 1024. The -ORBInitialPort option is used to override the default port number in this example. The following instructions assume you can use port 1050 for the Java IDL name server. You can substitute a different port if necessary. When running these examples on a Windows machine, subtitute a backslash (\) in path names. Change to the directory that contains the file Hello.idl. Run the IDL-to-Java compiler, idlj, on the IDL file to create stubs and skeletons.
idlj -fall Hello.idl
You must use the -fall option with the idlj compiler to generate both client and server-side bindings. For more information on the idlj options, link to IDL-to-Java compiler options. The idlj compiler generates a number of files. The actual number of files generated depends on the options selected when the IDL file is compiled. The generated files provide standard functionality, so you can ignore them until it is time to deploy and run your program. The files generated by the idlj compiler for Hello.idl, with the -fall command line option, are: _HelloImplBase.java This abstract class is the server skeleton, providing basic CORBA functionality for the server. It implements the Hello.java interface. The server class HelloServant extends _HelloImplBase. _HelloStub.java This class is the client stub, providing CORBA functionality for the client. It implements the Hello.java interface. Hello.java This interface contains the Java version of our IDL interface. The Hello.java interface extends org.omg.CORBA.Object, providing standard CORBA object functionality. HelloHelper.java This final class provides auxiliary functionality, notably the narrow() method required to cast CORBA object references to their proper types. HelloHolder.java This final class holds a public instance member of type Hello. It provides operations for out and inout arguments, which CORBA allows, but which do not map easily to Java's semantics. HelloOperations.java This interface contains the single method sayHello(). The IDL-to-Java mapping puts all of the operations defined on the IDL interface into this file, which is shared by both the stubs and skeletons. Compile the .java files, including the stubs and skeletons (which are in the directory HelloApp):
javac *.java HelloApp/*.java
Start the Java IDL Name Server. To do this from a UNIX command shell, enter:
tnameserv -ORBInitialPort 1050&
From an MS-DOS system prompt (Windows), enter:
start tnameserv -ORBInitialPort 1050
Note that 1050 is the port on which you want the name server to run. If you do not specify this, port 900 will be chosen by default. Also note that when using Solaris software, you must become root to start a process on a port under 1024. For this reason, we recommend that you use a port number greater than or equal to 1024. Start the Hello server:
java HelloServer -ORBInitialHost namerserverhost -ORBInitialPort 1050
Note that nameserverhost is the host on which the IDL name server is running. You can omit -ORBInitialHost nameserverhost if the name server is running on the same host as the Hello server. You can leave out -ORBInitialPort 1050 if the name server is running on the default port. Run the Hello application client or applet from a different shell than the server: To run the client application, From another DOS prompt or shell, type: java HelloClient -ORBInitialHost namerserverhost -ORBInitialPort 1050
Note that nameserverhost is the host on which the IDL name server is running. You can omit -ORBInitialHost nameserverhost if the name server is running on the same host as the Hello client. You can leave out -ORBInitialPort 1050 if the name server is running on the default port. To run the applet from the appletviewer, Open another prompt or shell. Change to the applet directory, HelloApp. Start the appletviewer and browse Tutorial.html by typing: appletviewer Tutorial.html When you have finished this tutorial, be sure to shut down the server, or to kill the server process. From a DOS prompt, select the window that is running the server and enter Ctrl+C. From a Unix shell, find the process, and select Kill. The server will continue to wait for invocations until it is explicitly stopped. Running the Hello World Application on 2 Machines describes one way of distributing the simple application across two machines - a client and a server. Home Copyright © 1995-2000 Sun Microsystems, Inc. All Rights Reserved.