要想使用ice首先要编写slice文件:示例:
#ifndef PERSON
#define PERSON
#include "persondefine.ice"
module hello
{
//structure definition
struct Person
{
string name;
long size;
};
sequence<IEDFAULTARC> IedFaultarcSeq;
interface iedComm
{
//你的接口,所有被定义的接口都是虚函数,需要你自己在服务端代码中实现
void HelloWorld(int &i) throws CommError;
string Meet() throws CommError;
void Myprint(string str);
};
};
#endif
2.服务器端
m_communicator = communicator();
m_adapterIedFile = m_communicator->createObjectAdapterWithEndpoints((string)("person"), (string)("default -p 8080"));
person ptr= new Person();
m_adapterIedFile->add(ptr, communicator()->stringToIdentity("person"));
m_adapterIedFile->activate();
3.客户端
ic = Ice::initialize(argc, argv);
Ice::ObjectPrx base = ic->stringToProxy("person:default -p 8080");
person ptr= Person::checkedCast(base);
//此处指针可以调用你自己封装的接口,
4编译
略