We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I hava choosed --with-pgm this code can only send message,but cannot receive message
import zmq # 创建上下文 context_p = zmq.Context() context_s = zmq.Context() # 创建发布者 publisher = context_p.socket(zmq.PUB) publisher.bind("epgm://192.168.0.40;224.0.0.1:5555") # 使用您的本机网络接口和组播地址 # 创建订阅者 subscriber = context_s.socket(zmq.SUB) subscriber.connect("epgm://192.168.0.40;224.0.0.1:5555") # 使用相同的组播地址 # 订阅所有消息 subscriber.setsockopt_string(zmq.SUBSCRIBE, "") try: while True: # 发布消息 message = input("请输入要发布的消息:") publisher.send_string(message) # 接收并处理消息 received_message = subscriber.recv_string() print(f"接收到消息: {received_message}") except KeyboardInterrupt: pass # 关闭套接字和上下文 publisher.close() subscriber.close() context_p.term() context_s.term()
in C++,I meet the same problem. publisher.cpp
#include <zmq.hpp> #include <thread> #include <string> #include <iostream> int main() { // 创建 ZeroMQ 上下文 zmq::context_t context(1); // 创建 PGM 套接字,使用 PGM 协议 zmq::socket_t socket(context, zmq::socket_type::pub); socket.setsockopt(ZMQ_SNDHWM, 0); // 设置发送高水位标记,不限制发送队列大小 // 使用 pgm:// 协议绑定到组播地址和端口 // i hava tried socket.bind("epgm://eth0;239.255.0.1:5555"); socket.bind("epgm://192.168.0.40;239.255.0.1:5555"); std::string message = "Hello, multicast!"; while (true) { // 发送消息到组播地址 zmq::message_t zmqMessage(message.size()); memcpy(zmqMessage.data(), message.data(), message.size()); socket.send(zmqMessage); std::cout << "Sent: " << message << std::endl; // 休眠一段时间 std::this_thread::sleep_for(std::chrono::seconds(1)); } return 0; }
subscriber.cpp
#include <zmq.hpp> #include <string> #include <iostream> int main() { // 创建 ZeroMQ 上下文 zmq::context_t context(1); // 创建 PGM 套接字,使用 PGM 协议 zmq::socket_t socket(context, zmq::socket_type::sub); // 使用 pgm:// 协议连接到组播地址和端口 // i hava tried socket.connect("epgm://eth0;239.255.0.1:5555"); socket.connect("epgm://192.168.0.40;239.255.0.1:5555"); // 订阅所有消息 socket.setsockopt(ZMQ_SUBSCRIBE, "", 0); while (true) { zmq::message_t zmqMessage; socket.recv(&zmqMessage); std::string message(static_cast<char*>(zmqMessage.data()), zmqMessage.size()); std::cout << "Received: " << message << std::endl; } return 0; }
The text was updated successfully, but these errors were encountered:
I meet the same problem. May I ask how you solved it?
Sorry, something went wrong.
epgm protocol is not supported when subscriber and publisher is on the same machine. Try to use ipc for that case.
No branches or pull requests
I hava choosed --with-pgm
this code can only send message,but cannot receive message
in C++,I meet the same problem.
publisher.cpp
subscriber.cpp
The text was updated successfully, but these errors were encountered: