最是人间留不住,朱颜辞镜花辞树。这篇文章主要讲述C++使用ICE实现两台主机通信实例相关的知识,希望能为你提供帮助。
ice使用过程跟google protocol buffer、gsoap类似,都是先写一个类似配置文件的东西,然后使用提供的工具生成相应语言的代码。
ice先写一个后缀名为.ice的文件,然后使用slice2cpp.exe生产对应c++代码,如下
module MCal
interface Cal
int add(int num1,int num2);
int sub(int num1,int num2);
;
;
其中MCal是生成c++类的命名空间,Cal是生成类的名字,add和sub是定义类的两个方法。
【C++使用ICE实现两台主机通信实例】可以直接命令行执行slice2cpp Caculator.ice生成,也可以在vs中选择slice2cpp作为编译.ice的工具生成,下面是工具生成的代码
// **********************************************************************
//
// Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
//
// Ice version 3.6.3
//
// < auto-generated>
//
// Generated from file `Caculator.ice
//
// Warning: do not edit this file.
//
// < /auto-generated>
//
#ifndef __Caculator_h__
#define __Caculator_h__
#include < IceUtil/PushDisableWarnings.h>
#include < Ice/ProxyF.h>
#include < Ice/ObjectF.h>
#include < Ice/Exception.h>
#include < Ice/LocalObject.h>
#include < Ice/StreamHelpers.h>
#include < Ice/Proxy.h>
#include < Ice/GCObject.h>
#include < Ice/AsyncResult.h>
#include < Ice/Incoming.h>
#include < IceUtil/ScopedArray.h>
#include < IceUtil/Optional.h>
#include < Ice/StreamF.h>
#include < IceUtil/UndefSysMacros.h>
#ifndef ICE_IGNORE_VERSION
#if ICE_INT_VERSION / 100 != 306
#error Ice version mismatch!
#endif
#if ICE_INT_VERSION % 100 > 50
#error Beta header file detected
#endif
#if ICE_INT_VERSION % 100 < 3
#error Ice patch level mismatch!
#endif
#endif
namespace IceProxy
namespace MCal
class Cal;
void __read(::IceInternal::BasicStream*, ::IceInternal::ProxyHandle< ::IceProxy::MCal::Cal> & );
::IceProxy::Ice::Object* upCast(::IceProxy::MCal::Cal*);
namespace MCal
class Cal;
::Ice::Object* upCast(::MCal::Cal*);
typedef ::IceInternal::Handle< ::MCal::Cal> CalPtr;
typedef ::IceInternal::ProxyHandle< ::IceProxy::MCal::Cal> CalPrx;
void __patch(CalPtr& , const ::Ice::ObjectPtr& );
namespace MCal
class Callback_Cal_add_Base : virtual public ::IceInternal::CallbackBase;
typedef ::IceUtil::Handle< Callback_Cal_add_Base> Callback_Cal_addPtr;
class Callback_Cal_sub_Base : virtual public ::IceInternal::CallbackBase;
typedef ::IceUtil::Handle< Callback_Cal_sub_Base> Callback_Cal_subPtr;
namespace IceProxy
namespace MCal
class Cal : virtual public ::IceProxy::Ice::Object
public:
::Ice::Int add(::Ice::Int __p_num1, ::Ice::Int __p_num2)
return add(__p_num1, __p_num2, 0);
::Ice::Int add(::Ice::Int __p_num1, ::Ice::Int __p_num2, const ::Ice::Context& __ctx)
return add(__p_num1, __p_num2, & __ctx);
#ifdef ICE_CPP11
::Ice::AsyncResultPtr
begin_add(::Ice::Int __p_num1, ::Ice::Int __p_num2, const ::IceInternal::Function< void (::Ice::Int)> & __response, const ::IceInternal::Function< void (const ::Ice::Exception& )> & __exception = ::IceInternal::Function< void (const ::Ice::Exception& )> (), const ::IceInternal::Function< void (bool)> & __sent = ::IceInternal::Function< void (bool)> ())
return __begin_add(__p_num1, __p_num2, 0, __response, __exception, __sent);
::Ice::AsyncResultPtr
begin_add(::Ice::Int __p_num1, ::Ice::Int __p_num2, const ::IceInternal::Function< void (const ::Ice::AsyncResultPtr& )> & __completed, const ::IceInternal::Function< void (const ::Ice::AsyncResultPtr& )> & __sent = ::IceInternal::Function< void (const ::Ice::AsyncResultPtr& )> ())
return begin_add(__p_num1, __p_num2, 0, ::Ice::newCallback(__completed, __sent), 0);
::Ice::AsyncResultPtr
begin_add(::Ice::Int __p_num1, ::Ice::Int __p_num2, const ::Ice::Context& __ctx, const ::IceInternal::Function< void (::Ice::Int)> & __response, const ::IceInternal::Function< void (const ::Ice::Exception& )> & __exception = ::IceInternal::Function< void (const ::Ice::Exception& )> (), const ::IceInternal::Function< void (bool)> & __sent = ::IceInternal::Function< void (bool)> ())
return __begin_add(__p_num1, __p_num2, & __ctx, __response, __exception, __sent);
::Ice::AsyncResultPtr
begin_add(::Ice::Int __p_num1, ::Ice::Int __p_num2, const ::Ice::Context& __ctx, const ::IceInternal::Function< void (const ::Ice::AsyncResultPtr& )> &推荐阅读
- ACE之Reactor模式使用实例
- #导入Word文档图片# Linux下信号处理
- opencv 绘图及交互(python)
- linux下遍历目录和文件,删除过期天数目录或文件shell脚本
- Spring Cloud原理详解
- SSD+HDD双硬盘+MSI主板win8.1+ubuntu17.04双系统安装总结
- containerd系列(containerd 的容器管理)
- 解决ubuntu apt-get install出现E:Clould not get lock /var/lib/dpkg/lock
- Gossip数据传播协议