服务端:
package servant; import Ice.Current; import demo._PrinterDisp; public class PrinterI extends _PrinterDisp{ @Override public void printString(String s, Current __current) { System.out.println(s); } }
package server; import servant.PrinterI; public class Server { public static void main(String[] args) { int status=0; Ice.Communicator ic=null; try{ ic = Ice.Util.initialize(args); Ice.ObjectAdapter adapter = ic.createObjectAdapterWithEndpoints("SimplePrinterAdapter", "default -p 10000"); Ice.Object object = new PrinterI(); adapter.add(object, Ice.Util.stringToIdentity("SimplePrinter")); adapter.activate(); ic.waitForShutdown(); }catch(Ice.LocalException e){ e.printStackTrace(); status=1; }catch(Exception e){ System.err.println(e.getMessage()); status=1; }finally{ if(ic!=null){ ic.destroy(); } System.exit(status); } } }
package client; import demo.PrinterPrx; import demo.PrinterPrxHelper; public class Client { public static void main(String[] args) { int status=0; Ice.Communicator ic = null; try{ ic = Ice.Util.initialize(); Ice.ObjectPrx base = ic.stringToProxy("SimplePrinter:default -p 10000"); PrinterPrx printer = PrinterPrxHelper.checkedCast(base); if(printer==null){ throw new Error("null proxy"); } printer.printString("hello world!"); }catch(Ice.LocalException e){ e.printStackTrace(); status=1; }catch(Exception e){ System.err.println(e.getMessage()); status=1; }finally{ if(ic!=null){ ic.destroy(); } System.exit(status); } } }
原文地址:http://blog.csdn.net/u012516914/article/details/45668889