C++使用ICE实现两台主机通信实例
Posted shixin_0125
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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是定义类的两个方法。
可以直接命令行执行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>
//
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);
::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&)>& pyton 编写脚本检测两台主机之间的通信状态,异常邮件通知