打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
ICE
module   Demo {
     interface   Printer {
         void   printString( string   s);
     };
};
之后插件会自动生成对应的.h,.cpp文件(编译器会报很多错误,这应该是个BUG,比较烦。留下cpp,h文件,从工程中移除ice文件,就没这些错误了。)

之后修改main函数,代码如下。
#include <Ice/Ice.h>
#include <Printer.h>
 
using   namespace   std;
using   namespace   Demo;
 
class   PrinterI :  public   Printer {
public :
     virtual   void   printString( const   string& s,   const   Ice::Current&);
};
 
void  
PrinterI::
printString( const   string& s,  const   Ice::Current&)
{
     cout <<'server:'<< s << endl;
}
 
int
main( int   argc,  char * argv[])
{
     int   status = 0;
     Ice::CommunicatorPtr ic;
     try   {
         ic = Ice::initialize(argc, argv);
         Ice::ObjectAdapterPtr adapter =
             ic->createObjectAdapterWithEndpoints( 'SimplePrinterAdapter' 'default -p 10000' );
         Ice::ObjectPtr object =  new   PrinterI;
         adapter->add(object, ic->stringToIdentity( 'SimplePrinter' ));
         adapter->activate();
         ic->waitForShutdown();
     catch   ( const   Ice::Exception& e) {
         cerr << e << endl;
         status = 1;
     catch   ( const   char * msg) {
         cerr << msg << endl;
         status = 1;
     }
     if   (ic) {
         try   {
             ic->destroy();
         catch   ( const   Ice::Exception& e) {
             cerr << e << endl;
             status = 1;
         }
     }
     return   status;
}
ICE程序运行时,需要DLL库。可以设置环境变量,也可以直接将DLL库拷贝到程序目录。
set ICE_HOME=C:\Program Files (x86)\ZeroC\Ice-3.6.4

我们编译的是vs2015 x86版本,因此C:\Program Files (x86)\ZeroC\Ice-3.6.4\bin\vc140目录下的库。带d的代表debug版本,不带d的代表release版本
测试程序,比较简单。只需要把ice36d.dll,iceutil36d.dll两个库。
三.编写nodejs客户端
1.首先安装ICE的JS包
npm install ice@3.6.4
2.把ice文件(Printer.ice)编译出js版本代码,命令行输入
slice2js Printer.ice
得到Printer.js文件
3.编写client.js,代码如下
var   Ice = require( 'ice' ).Ice;
var   Demo = require( './Printer' ).Demo;
var   ic;
Ice.Promise. try (
     function ()
     {
         ic = Ice.initialize();
         var   base = ic.stringToProxy( 'SimplePrinter:default -p 10000' );
         return   Demo.PrinterPrx.checkedCast(base).then(
             function (printer)
             {
                 return   printer.printString( 'Hello World!' );
             });
     }
).finally(
     function ()
     {
         if (ic)
         {
             return   ic.destroy();
         }
     }
).exception(
     function (ex)
     {
         console.log(ex.toString());
         process.exit(1);
     });
打开C++的控制台程序,运行node.js
node client.js
就可以看到控制台上打印出
server:Hello World!
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
ICE 在客户端中如何定位服务器
PHP中间件
ICE专题:使用C#编写ICE分布式应用程序
ICE—互联网通信引擎的学习笔记 - 空山雪林通用模块设计工作室 - JavaEye技术网站
人人网中间层-系统架构
Ice简介+Qt代码示例
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服