ICE初步----VS2008下的安装及实现hello world简单例子
来源:互联网 发布:caffe训练mnist 详解 编辑:程序博客网 时间:2024/05/29 11:29
ICE中间件 简介 略。
VS2008下安装:
1,http://www.zeroc.com/download.html下载Ice-3.4.2.msi,并安装。
2,设置环境变量PATH,如:INSTALLPATH = C:\Program Files (x86), 将C:\Program Files (x86)\ZeroC\Ice-3.4.2\bin添加至path变量中,如果不加,使用slice2cpp.exe时麻烦些,而且运行程序会由于找不到dll而无法启动。
3,配置VC目录。 添加include和lib目录。
4,“工具” -------> “ICE configuration” -----------> 勾选 “enable ice builder”
安装完成之后,完成一个客户端传送hello ice 的简单例子(配合ICE文档来实践入门)。
1,编写slice文件,然后编译生成.h和.cpp,构建proxy/skeleton
新建文件:print.ice ,内容如下:
module Demo { interface Printer { void printString(string s); };};
然后使用slice2cpp.exe进行编译:
之后,在D盘中就新增print.h/cpp两个文件。
2,编码实现服务端和客户端。
创建两个项目,并将步骤一中的两个文件分别添加至项目中。
服务端代码:
#include "stdafx.h"#include <Ice/Ice.h>#include "print.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 << s << endl;}intmain(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;}
客户端:
#include "stdafx.h"#include <Ice/Ice.h>#include "Print.h"using namespace std;using namespace Demo;intmain(int argc, char* argv[]){int status = 0;Ice::CommunicatorPtr ic;try {ic = Ice::initialize(argc, argv);Ice::ObjectPrx base = ic->stringToProxy("SimplePrinter:default -p 10000");PrinterPrx printer = PrinterPrx::checkedCast(base);if (!printer)throw "Invalid proxy";printer->printString("Hello ICE!");} catch (const Ice::Exception& ex) {cerr << ex << endl;status = 1;} catch (const char* msg) {cerr << msg << endl;status = 1;}if (ic)ic->destroy();return status;}
3,编译链接,运行OK。
ICE文档看起来挺吃力,先通过这个小例子简单认识一下。
- ICE初步----VS2008下的安装及实现hello world简单例子
- vs2008 下使用ICE 的Hello world 程序
- ICE第二篇--一个"hello world"的简单例子
- 简单的ICE通信应用-Hello World
- 安装ice-3.4.0,并运行demo里的hello world例子,java
- C语言学习之1(Microsoft Visual Studio即VC6软件的安装及hello world 简单例子编写)
- 一个简单的例子Docker Hello World
- 从Red5的win版本安装到简单的hello world例子
- 从Red5的win版本安装到简单的hello world例子
- win7下IE调用ActiveX的Hello World(VS2008)
- Ubuntu 下 简单的hello world 驱动
- ubuntu下编写简单的hello world
- ICE: Hello, World
- ICE C++ Hello World
- 简单的 Nodejs jade 实现Hello world
- 最简单的例子:Equinox 之 Hello World
- 简单修改gem5的默认例子hello world
- 简单的hello world
- Spring acegi 安全框架
- linux服务自动启动功能
- Android引入第三方jar的问题
- Ruby on Rails,使用save和update_attributes更新持久化的ActiveRecord对象
- Unicode字符编码区间表
- ICE初步----VS2008下的安装及实现hello world简单例子
- audo fdisk -l 查看硬盘区分表
- 从成都走向世界:6位85后创业者的创业历程
- struts2 使用 jakarta 上传文件时commons fileupload的异常捕捉(转自alfred.w)
- db 错的原因
- vim格式化代码
- 随笔--android中修改SeekBar控件默认显示
- 键码
- Tcp三卷书(卷一)——第一章总结