Linux下ZMQ的安装-创新互联
一、编译安装
1.1、安装依赖
网页题目:Linux下ZMQ的安装-创新互联
标题链接:http://hbruida.cn/article/deojpg.html
sudo apt-get install libtool pkg-config build-essential autoconf automake
1.2、编译安装ZMQ使用的加密库git clone git://github.com/jedisct1/libsodium.git
cd libsodium
./autogen.sh
./configure
make check
sudo make install
sudo ldconfig
cd ../
1.3、编译安装libzmqgit clone git://github.com/zeromq/libzmq.git
cd libzmq
./autogen.sh
./configure –with-libsodium
make
sudo make install
sudo ldconfig
cd ../
1.4、安装ZMQ的c库添加编译选项-lczmq -lzmq。
git clone git://github.com/zeromq/czmq.git
cd czmq
./autogen.sh
./configure && make check
sudo make install
sudo ldconfig
cd -
1.5、添加ZMQ的C++库git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh # bootstrap-vcpkg.bat for Powershell
./vcpkg integrate install
./vcpkg install cppzmq
cd -
二、使用
2.1、cmake使用cmake下使用,需要再CMakeList文件中添加如下内容:
#find cppzmq wrapper, installed by make of cppzmq
find_package(cppzmq)
target_link_libraries(*Your Project Name* cppzmq)
2.2、实例C++开发可以参考如下实例代码进行开发工作:
server端:
#includeint main()
{
zmq::context_t ctx;
zmq::socket_t sock(ctx, zmq::socket_type::push);
sock.bind("inproc://test");
sock.send(zmq::str_buffer("Hello, world"), zmq::send_flags::dontwait);
}
Client端:
#include#includeint main()
{
zmq::context_t ctx;
zmq::socket_t sock1(ctx, zmq::socket_type::push);
zmq::socket_t sock2(ctx, zmq::socket_type::pull);
sock1.bind("tcp://127.0.0.1:*");
const std::string last_endpoint =
sock1.get(zmq::sockopt::last_endpoint);
std::cout<< "Connecting to "
<< last_endpoint<< std::endl;
sock2.connect(last_endpoint);
std::arraysend_msgs = {
zmq::str_buffer("foo"),
zmq::str_buffer("bar!")
};
if (!zmq::send_multipart(sock1, send_msgs)) {
return 1;
}
std::vectorrecv_msgs;
const auto ret = zmq::recv_multipart(
sock2, std::back_inserter(recv_msgs));
if (!ret) {
return 1;
}
std::cout<< "Got "<< *ret
<< " messages"<< std::endl;
return 0;
}
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧
网页题目:Linux下ZMQ的安装-创新互联
标题链接:http://hbruida.cn/article/deojpg.html