Wapiti
Wapiti

Reputation: 1911

How to handle multiple publishers on same port in zmq?

This question has been asked before, here. I have the exact same problem. I want to publish from a bunch of different processes, and use the same port every time.

I tried the solution presented in the answer, but this did not work for me. I get the error

    File "/usr/local/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
    self.run()
  File "/usr/local/lib/python2.7/multiprocessing/process.py", line 114, in run
    self._target(*self._args, **self._kwargs)
  File "/home/akay/afk/multi.py", line 18, in to_zmq
    socket.connect("tcp://*:%s" % port)
  File "zmq/backend/cython/socket.pyx", line 478, in zmq.backend.cython.socket.Socket.connect (zmq/backend/cython/socket.c:4308)
ZMQError: Invalid argument

My code is like this, essentially taken straight from the example in the zmq docs here and here:

# Socket to talk to server
port = '5556'
context = zmq.Context()
socket = context.socket(zmq.SUB)
print "Listening for stream...", m
socket.bind("tcp://localhost:%s" % port) #change connect to bind, as per answer above
socket.setsockopt(zmq.SUBSCRIBE, topicfilter)

I am using python 2.7, and the most recent version of zmq. Any idea what I might be doing wrong?

Upvotes: 5

Views: 5949

Answers (1)

Peque
Peque

Reputation: 14811

Well, the error is clear:

    [...]
    socket.connect("tcp://*:%s" % port)
    [...]
ZMQError: Invalid argument

You can't connect to *, you must specify an IP address (the server IP address). If both the client and the server run on a single machine, try with localhost or 127.0.0.1.

Upvotes: 3

Related Questions