#include <Ice/Ice.h>
#include <foo.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("SimpleFoo:default -h localhost -p 10000");
FooPrx foo = FooPrx::checkedCast(base);
if (!foo)
throw "Invalid proxy";
cout << "name: " << foo->getName(10) << endl;
}
catch (const Ice::Exception &ex)
{
cerr << ex << endl;
status = 1;
}
catch (const char *msg)
{
cerr << msg << endl;
status = 1;
}
if (ic)
{
try
{
ic->destroy();
}
catch (const std::string &msg)
{
cerr << msg << endl;
status = 1;
}
}
return status;
}
---------------------- server.cpp -------------------------
#include <Ice/Ice.h>
#include <foo.h>
using namespace std;
using namespace Demo;
class FooI : virtual public Foo
{
public:
virtual std::string getName(Ice::Int value, const Ice::Current&);
};
std::string
FooI::getName(Ice::Int value, const Ice::Current&)
{
cout << "value: " << value << endl;
return "kasicass";
}
int main(int argc, char *argv[])
{
int status = 0;
Ice::CommunicatorPtr ic;
try
{
ic = Ice::initialize(argc, argv);
Ice::ObjectAdapterPtr adapter = ic->createObjectAdapterWithEndpoints(
"SimpleFooAdapter", "default -h localhost -p 10000");
Ice::ObjectPtr obj = new FooI;
adapter->add(obj, ic->stringToIdentity("SimpleFoo"));
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)
{
try
{
ic->destroy();
}
catch (const std::string &msg)
{
cerr << msg << endl;
status = 1;
}
}
return status;
}
------------------------ server/client run ----------------
D:\sandbox\ice\hello\debug>server.exe
value: 10
D:\sandbox\ice\hello\debug>client.exe
name: kasicass
D:\sandbox\ice\hello\debug>
--------------------------------------------------------------
本来是个很简的事情,但我悲剧地使用了vs2005 + debug mode,编译出来的东西直接crash了,提示 0xc0150002 错误。
后来发现是 vs2005 sp1 的问题,一定要用 sp1 且要用 release mode。release mode 编译,客户端一连接上来,继续crash。
无奈,安装了 vs2008,一切ok。然后 vs2005 再编译,kao,居然也好了。nndx
评论