Notes
Hello.ice #ifndef simple_ice#define simple_ice//name space or package name Module demo.slice.hello{interface hello{void printstring (str ing s); };};
#endif
/** * @author MUDFISHCN * * Servant Class:helloi * _hellodisp base class is generated by the Slice2java compiler, which is an abstract class. * _hellodisp abstract class contains a printstring () method. */public class Helloi extends _hellodisp {
/** * @author mudfishcn * version:1.0.1 */public class HelloServer { The public static void main (string[] args) { //Defines the status variable, which is used to control the server . int status = 0; Ice.communicator IC = null; Declares a Communicator object ic try { //Initialization of the ICE runtime IC = Ice.Util.initialize (args); /* * Create an Object adapter (Objectadapter) object Ioadapter and initialize it. * parameter "Helloworldadapter": Indicates the name of the adapter. * parameter "default-p 10000": Indicates that the adapter uses the default protocol (TCP/IP) listens for incoming requests at Port 10000. * Server Configuration complete . */ Ice.objectadapter ioadapter = ic.createobjectadapterwithendpoints ( "Helloworldadapter", "default-p 10000 ");
/* * Create a servant. for the Hello interface */ Ice.object IObject = ( Ice.object) New Helloi (); /* * Add new servant to adapter, * and named this new servant "HelloWorld" */ Ioadapter.add (Iobject, Ice.Util.stringToIdentity (" HelloWorld "); /* * Activation adapter, To enable the server to start processing requests from customers / ioadapter.activate ();
/* * suspend the calling thread until the server implementation terminates . terminate the server by issuing an instruction that calls off the runtime (run time) . */ Ic.waitforshutdown (); } catch (Localexception e) { //Capture all exceptions that may be thrown when the ice is run E.printstacktrace (); status = 1; } catch (Exception e) { //Capture string Constants e.printstacktrace (); status = 1; } Finally { if (IC!= null) { Ic.destroy (); } } system.exit (status); }}
Helloclient.java
Package demo.ice.Hello.client;
/** * @author mudfishcn */public class helloclient { public static void main ( String[] args) { int status = 0; String s; //Creating an object for a communicator ic Ice.communicator ic = null; try { //Initialization of the ICE runtime IC = Util.initialize (args); /* * Get proxy * For remote object to create a proxy object, and the Stringtoproxy () method of the Communicator is used to initialize it. * Parameters:"Helloworld:default-p 10000" * means: */ objectprx base = Ic.stringtoproxy ("helloworld:default-p 10000"); /* * Key points */ helloprx Hello = helloprxhelper.checkedcast (base); //test whether the downward conversion was successful. If the exception information is not thrown successfully "Invalid proxy" . if (hello = = null) { throw new Error (" Invalid proxy "); } // Send 10 messages to server for (int i=1;i<=10;i++) { s = "hello,world!" +integer.tostring (i); Hello.printstring (s); } } catch ( Ice.localexception e) { e.printStackTrace (); status = 1; } catch (Exception e) { E.printstacktrace (); status = 1; } finally { if (IC!= null) { /Destroy Communication connection Ic.destroy (); } } System.exit ( status); }}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.