3

我正在寻找一个允许我在另一个进程(在 Windows 上)中调用对象的成员函数的 RPC 库。

我目前遇到的问题是一些服务器端对象已经存在并且有多个实例。服务器应该能够将指针/标识符传递给客户端,客户端实现代理,然后将调用定向到远程对象实例。所以我基本上想要的是这样的:

Client:
TestProxy test = RemoteTestManager.GetTestById(123);
test.echo("bla");

其中 Test 的实例已经存在于服务器上,而 RemoteTestManager 是客户端在另一个 rpc 调用中获得的服务器上的管理器类。此外,它最好在命名管道上运行,因为同一台机器上可以有多个服务器(实际上我想要更像一个简单的 IPC:D)。

所以我的问题实际上是:C++ 是否有类似的东西,还是我必须自己编写一个

4

5 回答 5

2

就跨网络协议缓冲区的低级序列化消息而言,这是一种常见的选择......

http://code.google.com/p/protobuf/

如需更完整的 RPC 堆栈,请查看 Apache Thrift...

http://thrift.apache.org/

于 2012-05-01T00:19:16.903 回答
1

COM 怎么样?似乎完全符合您的要求。

于 2012-05-01T05:00:10.193 回答
1

您可能已经找到了解决方案。仅供参考,我创建了一个与您在此处询问的内容相匹配的库。看看CppRemote库。该库具有以下与您的描述相匹配的功能:

  • 按名称(std::string)获取指向服务器对象的指针。
  • 在服务器上绑定现有对象(非侵入式),然后从客户端获取该对象的代理。
  • 服务器可以绑定到多个现有对象的实例。
  • 它已命名管道传输。
  • 轻巧且易于使用。

服务器代码

Test test1, test2;
remote::server svr;
svr.bind<itest>(&test1, "test1");
svr.bind<itest>(&test2, "test2");
svr.start(remote::make_basic_binding<text_serializer, named_pipe_transport>("pid"));
...

客户代码

remote::session client;
client.start(remote::make_basic_binding<text_serializer, named_pipe_transport>("pid"));

auto test1 = client.get<itest>("test1");
auto test2 = client.get<itest>("test2");
test1->echo("bla");
test2->echo("bla");
于 2013-12-10T19:47:17.057 回答
0

ZeroMQ可能是目前最好的 IPC 系统,它允许客户端/服务器拓扑的多种组合。它也非常快速和高效。

你如何访问服务器对象取决于它们是如何实现的,CORBA 有这个功能,但我现在不会尝试使用 CORBA(或者然后是 TBH)。许多 RPC 系统允许您根据需要创建对象,或连接到单个实例。连接到为您创建并在该会话期间为每次调用保留的对象(即为每个客户端创建并保持活动的对象)仍然相当普遍。对象池也相当常见。但是,您必须管理这些服务器对象的生命周期,我不能真正建议您,因为您还没有说明如何管理您的对象。

我怀疑你想要命名管道,坚持 tcp/ip 连接 - 连接到 localhost 是一个非常轻量级的操作(COM 在这个配置中实际上是零开销)。

于 2012-04-30T21:48:28.737 回答
0

There are candidates on top of the list. But it depends on problem space. A quick look, Capnproto, by kenton varda, maybe a fit. CORBA is a bit old but used in many systems and frameworks such as ACE. One of the issues is PassByCopy of capability references which in capnproto PassByReference and PassByConstruction also provided. COM system also got some problems which needs it's own discussion. ZeroMQ is really cool which I caught a cold once. And it does not support RPC which means you have to implement it on level zero messaging. Also Google protobuf, kenton varda, could be a choice if you are not looking for features such as capabilities security, promise pipelining and other nice features provided by capnproto. I think you better give it a try and experiment yourself.

As a reminder, RPC is not only about remote object invocation. Areas of concern such as adequate level of abstraction and composition, pipelining, message passing, lambda calculus, capability security, ... are the important ones which have to be paid close attention. So, the better solution is finding the efficient and elegant one to your problem space.

Hope to be assistfull.

Bests, Omid

于 2019-09-19T15:54:53.603 回答