The publisher send a message. Sending takes place via the zeroqm library. The message is sent via msgpack. A created string file is packed and sent. The puplisher works great and sends out the messages.
The Subscriber receives the data. Error occurs during unpack:
Compiling works without errors. The programme is interrupted during the run in the line: msgpack::unpack(msg, static_cast<const char*>(got.data()), got.size());
the error is: msgpack::v1::insufficient_bytes
Publisher
#include <future>
#include <iostream>
#include <string>
#include <thread>
#include "zmq.hpp"
#include "zmq_addon.hpp"
#include<msgpack.hpp>
int main()
{
zmq::context_t ctx(1);
zmq::socket_t publisher(ctx, zmq::socket_type::pub);
std::stringstream ss;
publisher.bind("tcp://127.0.0.1:5041");
std::this_thread::sleep_for(std::chrono::milliseconds(500));
std::string msg_str = "Test";
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, msg_str);
zmq::message_t msg_send(sbuf.size());
memcpy(msg_send.data(), sbuf.data(), sizeof(sbuf));
while (true)
{
publisher.send(msg_send, zmq::send_flags::none);
std::cout << "Mitteilung ist online: " << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
}
Subscriber
#include <iostream>
#include<zmq.h>
#include<zmq.hpp>
#include<msgpack.hpp>
#include<vector>
#include<string>
#include <thread>
int main()
{
zmq::context_t ctx(1);
zmq::socket_t subscriber(ctx, zmq::socket_type::sub);
subscriber.connect("tcp://127.0.0.1:5041");
subscriber.set(zmq::sockopt::subscribe, "");
while (1)
{
std::string um_str_;
msgpack::unpacked msg;
zmq::message_t got;
subscriber.recv(got);
msgpack::object obj = msg.get();
std::cout << "Hier" << std::endl;
msgpack::unpack(msg, static_cast<const char*>(got.data()), got.size());
// obj.convert(um_str_);
}
}