简体   繁体   English

ZMQ PUSH PULL发送的每个消息的一半

[英]ZMQ PUSH PULL half of each message sent

I'm trying to send a stream of images, each one about 3.5Mb. 我正在尝试发送图像流,每个图像流约3.5Mb。 To send, I'm using code of the format: 要发送,我正在使用以下格式的代码:

zmq::socket_t sender (*context, ZMQ_PUSH);
sender.connect("tcp://....:5556");
while(...){
    zmq::message_t msg (data, (size_t)camHeight*camWidth, NULL,NULL);
    sender.send(msg, ZMQ_NOBLOCK);
}

And to receive: 并收到:

zmq::socket_t socket(zmqContext, ZMQ_PULL);
socket.bind("tcp://*:5556");
zmq::message_t msg;

while(..){
    socket.recv(&msg);
    unsigned char* data = (unsigned char*) msg.data();
    ...
    outFile.write ((char*) data, msg.size());
}

All of the images I'm expecting to come through do come through and the size of msg is as expected, however, the image is "clipped" - up to a horizontal line on the image (the same line in every image), the image is correct, and after that it is totally black. 我希望通过的所有图像都可以通过,并且味精的大小符合预期,但是,图像被“裁剪”了-直到图像上的水平线(每个图像中的同一行),图像是正确的,然后完全是黑色的。 Occasionally in the black section, there is some noise. 有时在黑色部分会有些杂音。

Does anyone have an idea of what might cause this? 有谁知道这可能是什么原因?

What might cause this? 是什么原因造成的? Wrong data manipulation, not ZeroMQ 错误的数据操作,而不是ZeroMQ

ZeroMQ sending functions ( in both of it's flavours, be it self-counting the data.sizeOf() or not ) move transparently & literally whatever you pass it to send. ZeroMQ发送函数(无论是两种类型,还是自计数data.sizeOf()都可以 透明且按字面意思进行传递。

As much bytes ( or as few bytes ) as it is instructed to send it does send. 指示发送的字节数(或字节数)确实发送。

No exceptions, no excuse. 没有例外,没有任何借口。

So if you instruct ZeroMQ to send only a fraction of the original, there you go. 因此,如果您指示ZeroMQ仅发送原始文件的一小部分,那么您就可以了。 You get just that fraction, that you have indicated ( be it intentionally or in error ). 您只得到了指示的分数(无论是有意还是有误)。


How to prove that? 如何证明呢?

Repair your data-" framing " ( in this case data-"cut-off" ) or use a safer-mode, self-wrapping container to deliver your content independently of it's variable sizing. 修复您的数据-“ 成帧 ”(在这种情况下为数据-“截止”),或使用安全模式,自动包装的容器来传递内容,而与可变大小无关。

If in doubts, just try to put your image-data into a JSON or even more human-readable case, store it inside a ZIP-file for such a test. 如有疑问,只需尝试将图像数据放入JSON或什至更易于阅读的情况下,将其存储在ZIP文件中以进行此类测试。

Then, move it accross the ZeroMQ messaging-layer and try to reconstruct the data from inside the JSON/ZIP-file. 然后,将其移动到ZeroMQ消息传递层上,并尝试从JSON / ZIP文件内部重构数据。

There you will notice the source of the cut-off failure -- the wrong calculus of the data-size. 在那里,您会注意到截止失败的根源-数据量计算错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM