namespace icetest { /**//// <summary> /// summary description for server. /// </summary> public class server { public server() { // // todo: add constructor logic here // }
public static void main(string[] args) { int status = 0; ice.communicator ic = null; try { ic = ice.util.initialize(ref args); ice.objectadapter adapter = ic.createobjectadapterwithendpoints( "simpleprinteradapter", "default -p 10000"); ice.object obj = new printeri(); adapter.add( obj, ice.util.stringtoidentity("simpleprinter")); adapter.activate(); ic.waitforshutdown(); } catch (exception e) { console.error.writeline(e); status = 1; } finally { if (ic != null) ic.destroy(); } environment.exit(status); } }
public class printeri : _printerdisp { public override void printstring(string s, ice.current current) { console.writeline(s); } } } 前面的代码都是例行公事,public class printeri : _printerdisp的代码才是我们需要的(简单吧!) 按照同样的方法,我们建立iceclienttest项目,先添加printer.cs文件,然后编写cient.cs文件,具体内容如下:
using system;
namespace iceclienttest { /**//// <summary> /// summary description for client. /// </summary> public class client { public client() { // // todo: add constructor logic here // }
public static void main(string[] args) { int status = 0; ice.communicator ic = null; try { ic = ice.util.initialize(ref args); ice.objectprx obj = ic.stringtoproxy( "simpleprinter:default -p 10000"); printerprx printer = printerprxhelper.checkedcast(obj); if (printer == null) throw new applicationexception("invalid proxy"); printer.printstring("hello world!"); } catch (exception e) { console.error.writeline(e); status = 1; } finally { if (ic != null) ic.destroy(); } environment.exit(status); } } }