在电脑上安装两个 安装包 Ice-3.5.1-VS2013.msi 和Ice-3.5.1.msi其中第一个文件的作用是 在 vs2013 的项目--》》属性中--》》ICE configration进行配置的界面。
然后把自己写的ICE程序放在这个 资源文件下,然后进行ICE 的配置,配置完成后会自动生成 h和.cpp文件。
然后再自己书写 server.cpp 具体书写内容全部摘录如下:
#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 << 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, adapter->getCommunicator()->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)
ic->destroy();
return status;
}
再自己书写 client.cpp 具体书写内容全部摘录如下:
#include <Ice/Ice.h>
#include <Printer.h>
using namespace std;
using namespace Demo;
int
main(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 World!");
} 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;
}
再分别运行服务器和客户端程序。
先运行服务器程序,再运行客户端程序,会在客户端程序上显示 hello world ,成功解决问题。
有些细节还没有说清,会在后期进行添加。