Skip to content
New issue

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

EPGM couldn't receive message under pub-sub mode #4747

Open
qdztxc opened this issue Oct 9, 2024 · 0 comments
Open

EPGM couldn't receive message under pub-sub mode #4747

qdztxc opened this issue Oct 9, 2024 · 0 comments

Comments

@qdztxc
Copy link

qdztxc commented Oct 9, 2024

Please use this template for reporting suspected bugs or requests for help.

Issue description

In pub-sub mode, use EPGM in same machine.

Environment

  • libzmq version (commit hash if unreleased): 4.3.6
  • OS: debian12

Minimal test code / Steps to reproduce the issue

publisher:

#include <zmq.hpp>
#include <string>
#include <iostream>
#include <thread>
#include <chrono>

int main() {
    zmq::context_t context(1);

    zmq::socket_t publisher(context, zmq::socket_type::pub);
    std::string connection_string = "epgm://eno1;239.192.1.1:5555";
    
    try {
        publisher.bind(connection_string);
        std::cout << "Publisher bound to " << connection_string << std::endl;
    } catch (zmq::error_t& e) {
        std::cerr << "Failed to bind publisher: " << e.what() << std::endl;
        return 1;
    }

    int count = 0;
    while (true) {
        std::string message = "Message " + std::to_string(count++);
        zmq::message_t zmq_message(message.data(), message.size());
        
        try {
            publisher.send(zmq_message, zmq::send_flags::none);
            std::cout << "Sent: " << message << std::endl;
        } catch (zmq::error_t& e) {
            std::cerr << "Failed to send message: " << e.what() << std::endl;
        }

        std::this_thread::sleep_for(std::chrono::seconds(1));
    }

    return 0;
}

subscriber:

#include <zmq.hpp>
#include <string>
#include <iostream>

int main() {
    zmq::context_t context(1);

    zmq::socket_t subscriber(context, zmq::socket_type::sub);
    std::string connection_string = "epgm://eno1;239.192.1.1:5555";
    
    try {
        subscriber.connect(connection_string);
        std::cout << "Subscriber connected to " << connection_string << std::endl;

        subscriber.set(zmq::sockopt::subscribe, "");
    } catch (zmq::error_t& e) {
        std::cerr << "Failed to connect subscriber: " << e.what() << std::endl;
        return 1;
    }

    while (true) {
        zmq::message_t message;
        try {
            auto result = subscriber.recv(message, zmq::recv_flags::none);
            if (result) {
                std::string received_msg(static_cast<char*>(message.data()), message.size());
                std::cout << "Received: " << received_msg << std::endl;
            }
        } catch (zmq::error_t& e) {
            std::cerr << "Failed to receive message: " << e.what() << std::endl;
        }
    }

    return 0;
}

What's the actual result? (include assertion message & call stack if applicable)

subscriber couldn't receive any message.

What's the expected result?

subscriber should recieve message sent by publisher.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant