zeromq / pyzmq

PyZMQ: Python bindings for zeromq
http://zguide.zeromq.org/py:all
BSD 3-Clause "New" or "Revised" License
3.69k stars 637 forks source link

BUG: ZMQ.HELLO_MSG #1973

Closed adhish9899 closed 5 months ago

adhish9899 commented 5 months ago

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

Issue description

I am getting ZMQError: Invalid argument when I am trying to use zmq.HELLO_MSG

Environment

ubuntu: 22.04 pyzmq.version = '25.1.2'

Minimal test code / Steps to reproduce the issue

import zmq
context = zmq.Context()
router = context.socket(zmq.ROUTER)

hello_msg = b"Hello, World!"
router.setsockopt(zmq.HELLO_MSG, hello_msg)

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

ZMQError: Invalid argument

What's the expected result?

somdoron commented 5 months ago

Hello message is for client / dealer / peer. When used, they will automatically send the hello message when connected or reconnected to the peer socket.

adhish9899 commented 5 months ago

@somdoron Thanks for the response, but I am still getting the same error for dealer.

import zmq
context = zmq.Context()
dealer = context.socket(zmq.DEALER)

hello_msg = b"Hello, World!"
dealer.setsockopt(zmq.HELLO_MSG, hello_msg)

ERROR MESSAGE

      3 dealer = context.socket(zmq.DEALER)
      5 hello_msg = b"Hello, World!"
----> 6 dealer.setsockopt(zmq.HELLO_MSG, hello_msg)

File _zmq.py:765, in zmq.backend.cython._zmq.Socket.set()

File _zmq.py:1367, in zmq.backend.cython._zmq._setsockopt()

File _zmq.py:164, in zmq.backend.cython._zmq._check_rc()

ZMQError: Invalid argument
minrk commented 5 months ago

zmq.HELLO_MSG is a draft socket feature, and only available if you have built libzmq with drafts enabled. pyzmq wheels do not have libzmq with unstable optional features enabled.

If you want to use draft features, you must install pyzmq from source after compiling libzmq with drafts enabled (pip install pyzmq --no-binary pyzmq, and make sure that zmq.has("draft") returns True.

adhish9899 commented 5 months ago

Thank you @minrk for your help.