1. Install ICE download Address: https://zeroc.com/download.html need to configure environment variables: Classpath add:%ice_home%/lib/db.jar;%i Ce_home%/lib/ice.jar path add:%ice_home%/bin;
cmd command: Slice2java appears the following screen to indicate successful installation:.
3. Hand-written ice files, note that the suffix named. Ice:message.ice, the contents of the document are as follows:
Module Message {Interface messagedemo{//interface class int maxnum (int a,int b);//interface method, parameter and return value is int}; };
4. Generate Java files: Cmd:slice2java message.ice
5. Next to write interface implementation class, you need to inherit such a class: _xxxxxxxxdisp:package Ice.message.impl; Import ice.current; Import Message._messagedemodisp; public class Messagei extends _messagedemodisp {@Override public int maxnum (int a, int B, current __current) {//TOD O auto-generated Method stub if (a>b) return A; else if (a<b) return B; else {System.out.println ("Sister's, they are incredibly big ...") "); return 0; } }
}
6. Service-Side code:
Package ice.message.server; Import Ice.message.impl.MessageI; Import Com.bean.PrinterI; public class Iceinit { public static void init () { int status = 0 &N Bsp ice.communicator IC = null; try { //at the beginning of the connection, args can be transmitted some of the first parameters, such as the connection timeout, the number of initial client connection pools, etc. ic = Ice.Util.initialize (); //Create an adapter named Meaaagedemoadapter and require the adapter to use the default protocol (TCP/IP listening port 10000 requests ) ice.objectadapter adapter = ic.createobjectadapterwithendpoints ( "Meaaagedemoadapter", "Default-h 10.0.67.106-p 10000"); //Instantiate a Messagei object, create a service object for the message interface &N Bsp ice.object Object = new Messagei (); //adds the service unit to the adapter and assigns the service object the name Meaaagedemo, which is used to uniquely determine a service unit Nbsp;adapter.add (object, Ice.Util.stringToIdentity ("Meaaagedemo")); //activation adapter, the advantage is that you can wait until all resources are in place to trigger the &N Bsp adapter.activate (); SYSTEM.OUT.PRINTLN ("Started Meaaagedemoadapter default-h 10.0.6 7.106-p 10000 "); //Let the service continue to monitor the request before exiting &NB Sp;ic.waitforshutdown ();  } catch (Ice.localexception e) { e.printstacktrace (); status = 1;  } catch (Exception e) { sy Stem.err.println (e.getmessage()); status = 1; &NBSP, &NBSP;IF (IC!= null) { //clean up // &NB Sp try { ic.destroy ();  } catch (Exception e) { &NBSP;SYSTEM.ERR.PRINTLN (E.getmessage ()); status = 1;   &NBSP} & nbsp system.exit (status); &NBSP} }
7: Client Invoke code:
Package ice.message.client; Import Java.lang.reflect.Method; public class Iceclient { public int maxnum (int a,int b) { int status = 0; &N Bsp int resultnum = 0; ice.communicator IC = null; try { //first-turn ic = Ice.Util.initialize (); //the name, network protocol, IP and port of the incoming Remote service unit, obtain the printer remote agent, the Stringtoproxy method used here & nbsp &NBSP;ICE.OBJECTPRX objectprx = Ic.stringtoproxy ("Meaaagedemo:default-h 10.0.6 7.106 -p 10000 "); //checkedcast down to get printer interface remote, and simultaneously detects whether the service unit obtained according to the incoming name is printer proxy interface, such as fruit is not the return null object & nbsp method method = Objectprx.GetClass (). GetMethod ("Maxnum", new class[] {integer.class,integer.class}); resultnum= (Integer) Method.invoke (objectprx, new object[] { A,b});  } catch (Ice.localexception e) { e.printstacktrace (); status = 1;  } catch (Exception e) { sy Stem.err.println (E.getmessage ()); status = 1; &NBSP, &NBSP;IF (IC!= null) { //clean up // &NB Sp try { ic.destroy (); &NBSP ; &NBSP} catch (Exception e) { system.er R.println (E.getmessage ()); status = 1;   &NBSP} & nbsp //System.exit (status); return resultnum; &NBSP} } **************************** Blue fonts can also be written like this *, but it is recommended that the first method ******************************** Message.messagedemoprx messagedemoprx = Message.messageDemoPrxHelper.checkedCast (base); if (messagedemoprx = null) throw new Error ("Invalid proxy"); //The Hello World to the service side, allowing the server to print, because this method will eventually execute the on the service side.   resultnum= &NBSP;MESSAGEDEMOPRX.M
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.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service