ICE 2.0 Learning Notes 1 (HelloWorld)

xiaoxiao2021-03-05  24

Hello.ice

#ifndef simple_ICE # define Simple_ICE // Name Space OR Package name Module Demo.slice.hello {interface hello {void printstring (string s);};}; #ENDIF

Server: helloi.java

Package demo.ice.hello.server; import demo.slice.hello._hellodisp; import ice.current; / ** * @Author mudfishcn * * servant class: helloi * _hellodisp base class is generated by the Slice2Java compiler, it is an abstraction class. * _Hellodisp abstract class contains a printstring () method. * / Public class HelloI extends _HelloDisp {/ * (non-Javadoc) * @see demo._HelloOperations # printString (java.lang.String, Ice.Current) * / public void printString (String s, Current __current) {// TODO Auto-generated method stub system.out.println (s);}} helloserver.java

Package demo.ice.hello.server; import ice.localexception; / ** * @Author mudfishcn * version: 1.0.1 * / public class helloserver {public static void main (string [] args) {// Define Status variables, Used to control the server. Int status = 0; Ice.communicator IC = null; // Declare a Communicator object IC try {// Initialize ICE runtime IC = Ice.util.initialize (args); / * * Create an object adapter (ObjectAdapter) Object IOADAPTER and initialize it. * Parameters "HelloWorDAdapter": indicates the name of the adapter. * Parameters "default -p 10000": indicates that the adapter uses the Default Protocol (TCP / IP) to listen in the port 10000.

The configuration server * * / Ice.ObjectAdapter IOAdapter = ic.createObjectAdapterWithEndpoints ( "HelloWorldAdapter", "default -p 10000");. / * * Create an interface to a Hello servant * / Ice.Object IObject = (Ice.Object). New Helloi (); / * * Add new servant to the adapter, * named this new servant * / Ioadapter.add (IObject, Ice.util.StringToIdentity)); / * * Activate the adapter so that the server starts processing request * / IADAPTER.Activate (); / * * hangs the thread that is sent until the server is terminated. * Or by sending a call to turn off the runtime (Run Time) The instruction to terminate the server. * / Ic.waitforshutdown ();} catch (localexception e) {// Capture all exceptions that may be thrown at the ICE runtime (); status = 1;} catch (Exception E ) {// capture string constant E.PrintStackTrace (); status = 1;} finally { IF (IC! = Null) {ic.destroy ();}} system.exit (status);}}}}} helloclient.java

转载请注明原文地址:https://www.9cbs.com/read-35980.html

New Post(0)