[zeromq-dev] zmq_setsockopt() returning invalid argument

suraj nellikar suraj.nellikar at gmail.com
Sun Feb 17 05:28:12 CET 2013

I am using zmq 3.2 library on Ubuntu (32 bit machine). I am trying to run a
test PUB-SUB model but the client is failing to set the sockopt to
ZMQ_SUBSCRIBE. Any idea what am I doing wrong here?

Here's the snippet of the code.
main() {
    void *context = zmq_ctx_new();
    void *req = zmq_socket(context,ZMQ_REQ);
    void *sub = zmq_socket(context,ZMQ_SUBSCRIBE);

    int rc = zmq_connect(req,"tcp://");
    printf("req connect, rc = %d\n",rc);
    rc = zmq_connect(sub,"tcp://");
    printf("sub connect, rc = %d\n",rc);
    uint64_t affinity = 1;
    rc = zmq_setsockopt (sub, ZMQ_AFFINITY, &affinity, sizeof affinity);
    //This works only when I use uint64_t for affinity. It fails for int.
    printf("setsockopt, rc = %d, errno = %s\n",rc,strerror(errno));
    rc = zmq_setsockopt(sub,ZMQ_SUBSCRIBE,"",0);
           //This always fails! rc is always -1
    printf("setsockopt, ZMQ_SUBSCRIBE = %d,rc = %d, errno =

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20130216/7a9e364f/attachment.html>

More information about the zeromq-dev mailing list