xcal
基于 C++23 的现代图形渲染引擎
载入中...
搜索中...
未找到
zmq.cc
浏览该文件的文档.
1// req_client.cpp
2#include <iostream>
3#include <nlohmann/json.hpp>
4#include <zmq.hpp>
5namespace json = nlohmann;
6
7int main() {
8 zmq::context_t ctx(1);
9 zmq::socket_t req(ctx, zmq::socket_type::req);
10 req.connect("tcp://127.0.0.1:5555"); // 连 Python REP 端口
11 json::json j = {{"name", "Alice"}, {"age", 25}};
12 req.send(zmq::buffer(j.dump()), zmq::send_flags::none);
13 std::cout << "[C++] sent: " << j.dump() << std::endl;
14
15 zmq::message_t reply;
16 if (req.recv(reply, zmq::recv_flags::none))
17 ;
18 std::cout << "[C++] recv ack: "
19 << std::string(static_cast<char*>(reply.data()), reply.size())
20 << std::endl;
21 return 0;
22}
int main()
Definition zmq.cc:7