[zeromq-dev] Send and receive using link-local IPv6 address using zmq 3.2.3 and czmq 1.4.1
Gerrit Hendrikus van Doorn
g.h.vandoorn at gmail.com
Wed Sep 10 07:49:35 CEST 2014
> And the same address? Those are not the most helpful examples to provide.
> Do the non-CZMQ versions work? Do you have ip6tables running?
I mentioned that I run the applications on the same machine (to simplify
the setup). I get the same results with ip6tables enabled or disabled.
What would be a better example?
eth0 Link encap:Ethernet HWaddr A0:D3:C1:04:9F:60
inet addr:134.63.132.24 Bcast:134.63.133.255 Mask:255.255.254.0
inet6 addr: fe80::a2d3:c1ff:fe04:9f60/64 Scope:Link
So, running them on the *same* machine with:
./zmq_server tcp://[::1]:54321
./zmq_client tcp://[fe80::a2d3:c1ff:fe04:9f60%%eth0]:54321
Results in the server binding correctly to [::1]:54321 but the client never
receiving anything (block on recv). When I run the client using:
./zmq_client tcp://[::1]:54321
I do receive data. However, I don't want to use the loopback address.
Non-CZMQ versions display the same behaviour (see examples below). If
these examples are not clear, let me know what you are expecting.
======== ZMQ client version ===========
#include <iostream>
#include <zmq.h>
#include <string.h>
static char *
s_recv (void *socket) {
char buffer [256];
int size = zmq_recv(socket, buffer, 255, 0);
if (size == -1)
return NULL;
if (size > 255)
size = 255;
buffer [size] = 0;
return strdup (buffer);
}
int main(int argc, char **argv) {
if (argc != 2) {
std::cout << "USAGE: prog tcp://localhost:12345" << std::endl;
return -1;
}
std::cout << "Binding to " << argv[1] << std::endl;
void *ctx = zmq_ctx_new();
void *reader = zmq_socket(ctx, ZMQ_PULL);
int val = 0;
zmq_setsockopt(reader, ZMQ_IPV4ONLY, &val, sizeof(int));
int rc = zmq_connect(reader, argv[1]);
if (rc == -1) {
std::cout << "Unable to connect to " << argv[1] << std::endl;
std::cout << zmq_strerror(zmq_errno()) << std::endl;
return -1;
}
std::cout << "Ready to receive data..." << std::endl;
char * str;
while ((str = s_recv(reader)) != nullptr) {
std::cout << str << std::endl;
}
zmq_close(reader);
zmq_ctx_destroy(ctx);
return 0;
}
======== ZMQ server version ===========
#include <iostream>
#include <zmq.h>
int main(int argc, char **argv) {
if (argc != 2) {
std::cout << "USAGE: prog tcp://localhost:12345" << std::endl;
return -1;
}
std::cout << "Binding to " << argv[1] << std::endl;
void *ctx = zmq_ctx_new();
void *writer = zmq_socket(ctx, ZMQ_PUSH);
int val = 0;
zmq_setsockopt(writer, ZMQ_IPV4ONLY, &val, sizeof(int));
int rc = zmq_bind(writer, argv[1]);
if (rc == -1) {
std::cout << "Unable to bind to " << argv[1] << std::endl;
std::cout << zmq_strerror(zmq_errno()) << std::endl;
return -1;
}
std::cout << "Ready to send data..." << std::endl;
while (rc != -1) {
rc = zmq_send(writer, "Hello", 6, 0);
}
zmq_close(writer);
zmq_ctx_destroy(ctx);
return 0;
}
On Tue, Sep 9, 2014 at 3:51 PM, Gerrit Hendrikus van Doorn <
g.h.vandoorn at gmail.com> wrote:
> Correction: I do use the same ports when testing (so both 55555 or 54321)
>
>
> On Tue, Sep 9, 2014 at 3:48 PM, Gerrit Hendrikus van Doorn <
> g.h.vandoorn at gmail.com> wrote:
>
>> Hi,
>>
>> I'm trying to use PUSH/PULL sockets over an IPv6 link-local address (on
>> the same machine). I wrote 2 small test applications to test which address
>> formats work, one pushing a string and the other receiving it. However, I
>> have not been able to get it to work using the link-local address.
>>
>> // ======== zmq_server ========
>> #include <iostream>
>> #include <czmq.h>
>> int main(int argc, char **argv) {
>> if (argc != 2) {
>> std::cout << "USAGE: prog tcp://localhost:12345" << std::endl;
>> return -1;
>> }
>> std::cout << "Binding to " << argv[1] << std::endl;
>> zctx_t *ctx = zctx_new ();
>> auto writer = zsocket_new (ctx, ZMQ_PUSH);
>> zsocket_set_ipv4only(writer, 0);
>> int rc = zsocket_bind(writer, argv[1]);
>> if (rc == -1) {
>> std::cout << "Unable to bind to " << argv[1] << std::endl;
>> return -1;
>> }
>> while (rc != -1) {
>> rc = zstr_send(writer, "HELLO");
>> }
>> zsocket_destroy (ctx, writer);
>> zctx_destroy (&ctx);
>> return 0;
>> }
>>
>> // ======== zmq_client ========
>> #include <iostream>
>> #include <czmq.h>
>> int main(int argc, char **argv) {
>> if (argc != 2) {
>> std::cout << "USAGE: prog tcp://localhost:12345" << std::endl;
>> return -1;
>> }
>> std::cout << "Connecting to " << argv[1] << std::endl;
>> zctx_t *ctx = zctx_new();
>> auto reader = zsocket_new(ctx, ZMQ_PULL);
>> zsocket_set_ipv4only(reader, 0);
>> int rc = zsocket_connect(reader, argv[1]);
>> if (rc == -1) {
>> std::cout << "Unable to connect to " << argv[1] << std::endl;
>> std::cout << zmq_strerror(zmq_errno()) << std::endl;
>> return -1;
>> }
>> while (rc != -1) {
>> auto str = zstr_recv(reader);
>> if (str == nullptr) {
>> return 0;
>> }
>> std::cout << "Received: " << str << std::endl;
>> }
>> zsocket_destroy(ctx, reader);
>> zctx_destroy(&ctx);
>> return 0;
>> }
>>
>> Usage (note the escaped % sign as czmq uses printf):
>> ./zmq_server tcp://[::1]:54321
>> ./zmq_client tcp://[fe80::a2d3:c1ff:fe04:9f60%%eth0]:55555
>>
>> The server and client never connect or receive data. They work fine using
>> IPv4.
>>
>> The applications run on the same machine (which has multiple interfaces).
>> I'm using zmq 3.2.3 and czmq 1.4.1.
>>
>> Any thoughts on what I'm doing wrong?
>>
>>
>>
>>
>>
>>
>
>
> --
> g.h.vandoorn at gmail.com
> +1.510.859.4618
>
--
g.h.vandoorn at gmail.com
+1.510.859.4618
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20140909/c94dd49d/attachment.htm>
More information about the zeromq-dev
mailing list