I am trying to send a video through a zmq server and I successfully got it with a 1gb video, but when I try to send a movie with, with a very larger size(6.7gb) I get the following error:
cliente: /usr/local/include/zmq.hpp:1958: zmq::recv_result_t zmq::detail::socket_base::recv(zmq::message_t&, zmq::recv_flags): Assertion `msg.size() == static_cast<size_t>(nbytes)' failed.
make: *** [Makefile:7: cliente] Aborted
make: *** Deleting file 'cliente'
So I tried to break the file on the server and send it separately to the client, but I got the same error. Does someone know how to separate the message_t to send it separately to the client?
This is the server code:
#include <fstream>
#include <sstream>
#include <chrono>
#include <thread>
#include <iostream>
#include <zmq.hpp>
using namespace std::chrono_literals;
int main()
{
zmq::context_t context(1);
zmq::socket_t socket(context, zmq::socket_type::rep);
socket.bind("tcp://*:5555");
std::ifstream img("video.mkv", std::ifstream::in | std::ios::binary);
for (;;)
{
zmq::message_t message;
socket.recv(message, zmq::recv_flags::none);
std::ostringstream os;
os << img.rdbuf();
std::string oss(os.str());
socket.send(zmq::buffer(oss.substr(0, (oss.size() / 2))), zmq::send_flags::sndmore);
std::this_thread::sleep_for(1s);
socket.send(zmq::buffer(oss.substr((oss.size() / 2), oss.size() - 1)), zmq::send_flags::none);
std::this_thread::sleep_for(1s);
}
}
This is my client:
#include <fstream>
#include <sstream>
#include <iostream>
#include <string>
#include <zmq.hpp>
int main()
{
std::ofstream img("teste.mkv", std::ios::out | std::ios::binary);
zmq::context_t context(2);
zmq::socket_t socket(context, zmq::socket_type::req);
socket.connect("tcp://localhost:5555");
zmq::message_t message_1, message_2;
socket.send(zmq::buffer("ok\n"), zmq::send_flags::none);
socket.recv(message_1, zmq::recv_flags::none);
std::string data_1(message_1.to_string());
img << data_1;
data_1.clear();
socket.recv(message_2, zmq::recv_flags::none);
std::string data_2(message_2.to_string());
img << data_2;
data_2.clear();
}
Aucun commentaire:
Enregistrer un commentaire