我需要从客户程序向服务器程序发出一个简单的单向指令(可能是一),提出在C++类型(序列化相当简单)。 C++,Windows XP+。
I m 寻找一个不需要复杂配置的图书馆,提供简单的接口,不要求学习时间,也不需要商业用途限制。 简单地解决简单问题。
我需要从客户程序向服务器程序发出一个简单的单向指令(可能是一),提出在C++类型(序列化相当简单)。 C++,Windows XP+。
I m 寻找一个不需要复杂配置的图书馆,提供简单的接口,不要求学习时间,也不需要商业用途限制。 简单地解决简单问题。
我不想再说一遍。 这些替代物都有自己的问题,而且与点名的管道、共享记忆等相比,它们得到更好的支持,因为几乎每个人都使用这些工具。 当地系统备案速度可能不是一个问题。
There sache Thrift:
http://incubator.apache.org/thrift/
在谷歌代陶器图书馆周围,有几处皇家骑士团的节目,作为拆散机制:
https://github.com/google/protobuf/blob/master/docs/third_parties.md#rpc-implementations
There s XML-RPC:
http://xmlrpc-c.sourceforge.net/
如果您的电文为really 简言之,我可能考虑使用UDP包,因此不存在管理联系。
You might like ZeroMQ for something like this. Perhaps not as much a complete RPC, as a raw byte messaging framework you could use to make an RPC. It s simple, lightweight and with an impressive performance. You can easilly implement an RPC on top of it. Here s an example server straight from the manual:
//
// Hello World server in C++
// Binds REP socket to tcp://*:5555
// Expects "Hello" from client, replies with "World"
//
#include <zmq.hpp>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
int main () {
// Prepare our context and socket
zmq::context_t context (1);
zmq::socket_t socket (context, ZMQ_REP);
socket.bind ("tcp://*:5555");
while (true) {
zmq::message_t request;
// Wait for next request from client
socket.recv (&request);
printf ("Received Hello");
// Do some work
sleep (1);
// Send reply back to client
zmq::message_t reply (5);
memcpy ((void *) reply.data (), "World", 5);
socket.send (reply);
}
return 0;
}
这一例子使用tcp://*.555555,但如果你使用,则使用效率更高的IPC技术:
socket.bind("ipc://route.to.ipc");
or even faster inter thread protocol:
socket.bind("inproc://path.for.client.to.connect");
如果你只需要支持的话 Windows I d 使用了RPC中建立的Windows,我撰写了两篇介绍性文章:
http://www.codeproject.com/KB/IP/rpcintro1.aspx
http://www.codeproject.com/KB/IP/rpcintro2.aspx
您可使用ncalrpc。 如果你只需要当地进程间通信,则需要礼宾。
Boost.MPI。 简单、快捷、可扩展。
#include <boost/mpi/environment.hpp>
#include <boost/mpi/communicator.hpp>
#include <iostream>
#include <sstream>
namespace mpi = boost::mpi;
int main(int argc, char* argv[])
{
mpi::environment env(argc, argv);
mpi::communicator world;
std::stringstream ss;
ss << "Hello, I am process " << world.rank() << " of " << world.size() << ".";
world.send(1, 0, ss.str());
}
如果你只处理窗户,而且确实需要C++接口,则使用COM/DCOM。 其基础是太平洋共同体秘书处(进而基于太平洋共同体秘书处)。
如果你需要时间学习基本知识,就非常简单。
也许你甚至不需要图书馆。 Windows有一个IPC机制深深地植入其核心的APIC(windows.h)。 你们基本上能够把窗户信息放在不同过程的主要窗口的电传中。 视窗甚至界定了一种标准信息,即:WM_COPYDATA。
派遣程序基本是:
接收过程(窗口):
I m用Raknet说是冰单,简单易懂。
也可看msg Pack-rpc。
A. 更新
While Thrift/Protobuf are more flexible, I think, but there are require to write some code in specific format. For example, Protobuf needs some .proto file, which can be compile with specific compiler from package, that genegate some classes. In some cases it might be more difficult that other parts of code. msgpack-rpc is much simpler. It doesn t require write some extra code. Here is example:
#include <iostream>
#include <msgpack/rpc/server.h>
#include <msgpack/rpc/client.h>
class Server: public msgpack::rpc::dispatcher {
public:
typedef msgpack::rpc::request request_;
Server() {};
virtual ~Server() {};
void dispatch(request_ req)
try {
std::string method;
req.method().convert(&method);
if (method == "id") {
id(req);
} else if (method == "name") {
name(req);
} else if (method == "err") {
msgpack::type::tuple<> params;
req.params().convert(¶ms);
err(req);
} else {
req.error(msgpack::rpc::NO_METHOD_ERROR);
}
}
catch (msgpack::type_error& e) {
req.error(msgpack::rpc::ARGUMENT_ERROR);
return;
}
catch (std::exception& e) {
req.error(std::string(e.what()));
return;
}
void id(request_ req) {
req.result(1);
}
void name(request_ req) {
req.result(std::string("name"));
}
void err(request_ req) {
req.error(std::string("always fail"));
}
};
int main() {
// { run RPC server
msgpack::rpc::server server;
std::auto_ptr<msgpack::rpc::dispatcher> dispatcher(new Server);
server.serve(dispatcher.get());
server.listen("0.0.0.0", 18811);
server.start(1);
// }
msgpack::rpc::client c("127.0.0.1", 18811);
int64_t id = c.call("id").get<int64_t>();
std::string name = c.call("name").get<std::string>();
std::cout << "ID: " << id << std::endl;
std::cout << "name: " << name << std::endl;
return 0;
}
产出
ID: 1
name: name
https://github.com/msg Pack/msg Pack-rpc/tree/master/cpp/test”rel=“nofollow” https://github.com/msg Pack/msg Pack-rpc/tree/master/cpp/test。
http://sourceforge.net/projects/xmlrpcc4win/"rel=“nofollow”
真正易于使用: 但是,这只是“,只有客户!。
也有Microsoft Messaging Queueing,这简直是在当地机器上使用的所有程序。
I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...
I have been searching for sample code creating iterator for my own container, but I haven t really found a good example. I know this been asked before (Creating my own Iterators) but didn t see any ...
Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...
I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?
Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...
Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...
I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...
Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?