我在Visual Code 2019中用pgm源代码编译zeromq c++源代码,并得到zeromq lib。 然后我配置了我的组播环境,但是程序加入组播失败。 我的代码是:
void* context = zmq_ctx_new();
void* socket = zmq_socket(context, ZMQ_SUB);
zmq_setsockopt(socket, ZMQ_SUBSCRIBE, "", 0);
zmq_setsockopt(socket, ZMQ_RATE, &RATE, sizeof(RATE));
const int32_t RCVBUF_SIZE = 1342177280;
zmq_setsockopt(socket, ZMQ_RCVHWM, &RCVBUF_SIZE, sizeof(RCVBUF_SIZE));
const int32_t SNDBUF_SIZE = 1342177280;
zmq_setsockopt(socket, ZMQ_SNDHWM, &SNDBUF_SIZE, sizeof(SNDBUF_SIZE));
// example: "epgm://192.168.65.132;224.0.22.1:9210"
const std::string protocol = "epgm";
int rc = zmq_connect(
socket, (protocol + "://" + local_ip + ";" + multicast_addr).c_str());`
调试的时候,发现失败了:
`int rc = pgm_receiver->init (udp_encapsulation, _addr->address.c_str ()); (from file session_base.cpp)`
继续调试过程,这里返回-1:
`retval = setsockopt (s, recv_level, MCAST_JOIN_GROUP, (const char*)gr, sizeof(struct group_req));(from file sockaddr.c89.c)`
如何解决这个问题?
原因及解决方法
这是一个未解决的错误:https://github.com/zeromq/libzmq/issues/4301。 您需要将 SOL_IP 替换为 IPPROTO_IP,并重新编译 pgm src。