Matthias Albrecht
Matthias Albrecht

Reputation: 41

How do I specify an IPv6 address for a ZeroMQ REQ/REP setup on a local machine?

I cannot get a zmq server and client to talk with IPv6, while it easily works with IPv4 with C++.

This is what my ip addr command shows:

2: enp0s31f6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 1c:1b:0d:0c:d7:bc brd ff:ff:ff:ff:ff:ff
    inet 192.168.35.208/24 brd 192.168.35.255 scope global dynamic enp0s31f6
       valid_lft 7193sec preferred_lft 7193sec
    inet6 fe80::fb7:c6df:9d3a:3d7b/64 scope link
       valid_lft forever preferred_lft forever

Server:

zmq::context_t context(1);
zmq::socket_t server(context, ZMQ_REP);

server.setsockopt(ZMQ_IPV6, 1);

server.bind("tcp://*:5555%enp0s31f6");

Client:

zmq::context_t context(1);
zmq::socket_t client(context, ZMQ_REQ);

client.setsockopt(ZMQ_IPV6, 1);

client.connect("tcp://[fe80::fb7:c6df:9d3a:3d7b]:5555%enp0s31f6");

The server waits listening, the clients sends the message, the server never gets it. IPv4 works nicely.

What is wrong?

Upvotes: 4

Views: 2157

Answers (1)

user3666197
user3666197

Reputation: 1

ZeroMQ API v4.2.2 specification says:

An interface may be specified by either of the following:

  • The wild-card *, meaning all available interfaces.
  • The primary IPv4 or IPv6 address assigned to the interface, in its numeric representation.
  • The non-portable interface name as defined by the operating system.

The 2nd option ought work, if IPv6 gets enabled:

client.setsockopt( ZMQ_IPV6, True );                        // ENABLE
client.connect( "tcp://[fe80::fb7:c6df:9d3a:3d7b]:5555" );  // SET

Upvotes: 6

Related Questions