gpt4 book ai didi

c++ - 带有 msgpack 的 ZeroMQ 在 C++ 中抛出无效参数错误

转载 作者:行者123 更新时间:2023-11-28 05:16:23 25 4
gpt4 key购买 nike

<分区>

我正在使用 zeromq 从使用 msgpack 进行序列化的应用程序中读取数据。该代码编译良好,但在运行时抛出无效参数错误。我哪里错了。

这里是错误:在抛出 'zmq::error_t' 实例后终止调用

what(): 无效参数中止(核心转储)

这是代码。

#include <zmq.hpp>
#include <iostream>
#include <sstream>
#include <msgpack.hpp>
#include <string>

int main(int argc, char *argv[]){
zmq::context_t context (1);

// Open a req port to talk to application
std::string addr = "tcp://127.0.0.1";
std::string req_port = "55555";
zmq::socket_t req (context, ZMQ_REQ);
req.connect(addr+req_port);

// Ask for the subport
zmq::message_t subPortRequest (8);
memcpy (subPortRequest.data(), "SUB_PORT", 8);
req.send(subPortRequest);

zmq::message_t reply;
req.recv(&reply);

std::string sub_port = std::string(static_cast<char*>(reply.data()), reply.size());
std::cout << sub_port << std::endl;


// Open a sub port to listen to application
zmq::socket_t sub (context, ZMQ_SUB);
std::cout << addr+sub_port << std::endl;
sub.connect(addr+sub_port);

// subscriptions to everything
sub.setsockopt(ZMQ_SUBSCRIBE, "", strlen(""));

while(1){
zmq::message_t reply_topic;
sub.recv(&reply_topic);
std::string topic = std::string(static_cast<char*>(reply_topic.data()), reply_topic.size());

zmq::message_t reply_msg;
sub.recv(&reply_msg);
std::string msg = std::string(static_cast<char*>(reply_msg.data()), reply_msg.size());

msgpack::object_handle oh = msgpack::unpack(msg.data(), msg.size());
msgpack::object obj = oh.get();
std::cout << obj << std::endl;

}

}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com