ZMQ Error 19 when binding ZMQ_PUB type socket

33 Views Asked by At

I have a simple code chunk that establishes a ZMQ_PUB type socket to broadcast data packets. However, I am finding that this code works on some Windows machines and not others.

Working machine details: ZMQ version 4.3.5, Windows 11. Not-working machine details: ZMQ version 4.3.5, Windows 10.

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

this->publisher_context = zmq_ctx_new();
this->publisher_socket = zmq_socket(this->publisher_context, ZMQ_PUB);
assert(this->publisher_socket);
std::string address = "tcp://localhost:5556";
int broadcastConnect = zmq_bind(this->publisher_socket, address.c_str());
if (broadcastConnect != 0) {
    int error_code = zmq_errno();
    std::string text = "Broadcast socket did not connect correctly. ZMQ error code: " + std::to_string(error_code);
    std::cout << text.c_str() << std::endl;
}

This code throws ZMQ Error 19 (ENODEV).

Things I have tried on the not-working machine:

  • Checked my open TCP port usage through cmd using netstat (port is not in use)
  • This address (tcp://localhost:5556) is available, I am able to instead create a ZMQ_REQ type socket on the same port. Binding the ZMQ_PUB errors out. This tells me that localhost is configured correctly. Additionally, replacing localhost in the address string with [::1] produces the same results.
  • Temporarily disabled my Windows Defender Firewall Domain/Private/Public profiles and rebooted, same results.

Things I'll try next:

  • Upgrade not-working machine to Windows 11, although I'd rather not if possible.
1

There are 1 best solutions below

0
jxof On

It turns out that either the port was secretly in use (but not reported by netstat), or that the port has restrictions on the socket type that can interface with it. Changing the port number from 5556 to 5570 resolved my issue. I do not know, however, what the root cause of this port being blocked was.