Install ICE3.5.1 On Ubuntu 16.04 with C++ run time
1.准备测试程序
1.1 编写ice文件
建立一个print目录,并在目录下建立ice文件demo.ice,代码如下:
module demo
{
interface printer
{
void printerstr(string msg);
};
};
1.2 编写ice服务端server.cpp
#include <Ice/Ice.h>
#include <demo.h>
using namespace demo;
using namespace std;
class PrinterI : public printer {
public:
virtual void printerstr(const string & s,
const Ice::Current &);
};
void PrinterI::printerstr(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,
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)
ic->destroy();
return status;
}