我正在寻找一个简单的套接字接口的C ++使用MS Visual C + + Express [英] I am looking for a simple socket interface for C++ using MS Visual C++ Express

查看:194
本文介绍了我正在寻找一个简单的套接字接口的C ++使用MS Visual C + + Express的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++中有没有一个简单的套接字接口,我可以使用MS Visual Studio Express版本?我知道有WinSock库,我想我正在寻找一个更容易使用的包装。

Is there a dead simple socket interface in C++ that I could use with MS Visual Studio Express Edition? I know there is the WinSock library, I guess I am looking for a wrapper around that which is simpler to use.

我认为java.net库足够简单,然而,MS VC ++ Express是我必须使用的。有没有什么等同的?

I would consider the java.net library simple enough, however, MS VC++ Express is what I have to use. Is there anything equivalent?

推荐答案

我曾经在套接字级别工作,如果这是你需要的,然后是Boost: :Asio是伟大的,如果有点混乱。

I used to work a lot at the socket level and if that's what you need then yes Boost::Asio is great, if a little confusing.

但是,如果你只需要在进程之间交付数据(在相同或不同的机器上),那么我会去进一步向上,看看像ØMQ;看看从另一个进程接收消息是多么容易:

However, if you just need to deliver data between processes (on the same or different machines) then I would go a bit further up the stack and look at something like ØMQ; take a look how easy it is to receive a "message" from another process:

zmq::context_t ctx(1);

zmq::socket_t sock(ctx, ZMQ_REQ);
sock.connect("tcp://localhost:5555");

zmq::message_t msg;
while(sock.recv(&msg)) {
    std::string s(static_cast<char*>(msg.data()), msg.size());
    std::cout << s;
}

发送同样简单。

zmq::context_t ctx(1);

zmq::socket_t sock(ctx, ZMQ_REP);
sock.bind("tcp://*:5555");

std::string s = "Hello you!";
zmq::message_t msg(s.size());
memcpy(msg.data(), s.data(), s.size());

while(true) {
    sock.send(msg);
    sleep(1);
}

ZeroMQ非常轻便,可以处理连接,重新连接,等等...所有你必须是你想要显示在管道的另一侧(在这种情况下,我们只是使用简单的字符串)的消息有效载荷。

ZeroMQ is very lightweight and takes care of connection, reconnection, transmission, framing, etc... All you have to have is your "message" payload that you want to show up on the other side of the pipe (in this case we just used simple strings).

它还负责许多更高级的消息传递技术,例如pub-sub(相同消息的多个接收器)。

It also takes care of a number of more advanced messaging techniques such as pub-sub (multiple receivers of the same messages).

这篇关于我正在寻找一个简单的套接字接口的C ++使用MS Visual C + + Express的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆