C++与GnuRadio通过ZeroMQ REQ通信失败问题求助
问题:C++ ZeroMQ代码无法向GnuRadio流图发送消息并显示
问题概述
我编写了C++代码通过ZeroMQ向GnuRadio流图发送字符串做测试,但GnuRadio的Message Debug模块始终无法显示消息。抓包确认消息已发送,用nc命令发送也存在同样问题,只有通过另一个GnuRadio流图的ZMQ REP Message Sink发送时,才能看到消息内容。
C++测试代码
#include <zmq.hpp> #include <iostream> #include <string> int main() { // Create a ZeroMQ context and a REQ socket zmq::context_t context(1); zmq::socket_t socket(context, zmq::socket_type::req); socket.connect("tcp://127.0.0.1:55555"); // Ensure this matches GNU Radio's address std::string msg_content = "Hello World"; // Create a ZeroMQ message with the content zmq::message_t request(msg_content.size()); memcpy(request.data(), msg_content.c_str(), msg_content.size()); // Send the message to GNU Radio socket.send(request, zmq::send_flags::none); // Receive the reply from GNU Radio (required for REQ socket) zmq::message_t reply; socket.recv(reply); return 0; }
GnuRadio流图配置
- 流图包含两个模块:
ZMQ REQ Message Source连接Message Debug ZMQ REQ Message Source的地址设置为tcp://127.0.0.1:55555
排查细节
- 通过TCP抓包确认:C++代码和
echo "Hello, World!" | nc 127.0.0.1 55555命令均已成功发送"Hello World"字符串 - 唯一能正常显示的场景:创建另一个GnuRadio流图,用
ZMQ REP Message Sink向目标流图发送消息时,Message Debug模块能显示内容
内容的提问来源于stack exchange,提问作者raff5184
相关产品推荐
相关产品推荐

