Reputation: 565
I got this error in my program:
Traceback (most recent call last):
File "scriptA.py", line 17, in <module>
socketPub.bind("tcp://localhost:%s"% portPub)
File "socket.pyx", line 434, in zmq.backend.cython.socket.Socket.bind (zmq/backend/cython/socket.c:3928)
File "checkrc.pxd", line 21, in zmq.backend.cython.checkrc._check_rc (zmq/backend/cython/socket.c:6058)
zmq.error.ZMQError: No such device
This is a simple script I have done to reproduce it:
import zmq
import random
import sys
import time
port = "5566"
if len(sys.argv) > 1:
port = sys.argv[1]
int(port)
portSub = "5556"
context = zmq.Context()
portPub = "5566"
#contextPub = zmq.Context()
socketPub = context.socket(zmq.PUB)
socketPub.bind("tcp://localhost:%s"% portPub)
socket = context.socket(zmq.SUB)
socket.connect("tcp://localhost:%s"% portSub)
socket.setsockopt(zmq.SUBSCRIBE,'')
while True:
socket.send("BB", zmq.SNDMORE)
socket.send("16", zmq.SNDMORE)
socket.send("14", zmq.SNDMORE)
socket.send("11", zmq.SNDMORE)
socket.send("4")
time.sleep(3)
I want to subscribe to one point and be able to send to another one. Is it possible? 2 differents end points. A sends to B and B sends to C.
Upvotes: 9
Views: 9505
Reputation: 1225
Your port numbers do not match. From your code:
portSub = "5556"
portPub = "5566"
So you are binding to one port and connecting to another. Make sure the ports match or simply do:
portSub = "5556"
portPub = portSub
Furthermore, I'm not sure if your binding-string "tcp://localhost:%s"% portPub
is correct. When working with ZMQ, I always use the Asterisk *
instead of localhost
or 127.0.0.1
. This always works for me and is something you can try if changing the port number does not make it work: "tcp://*:%s"% portPub
(or I prefer f'tcp://*:{portPub}'
, which is more readable I think). I think you have to use the binding-string I propose. Your connection-string seems to be fine.
Upvotes: 0
Reputation: 7180
Try to replace localhost
by 127.0.0.1
.
For more information, have a look at this stackoverflow thread
Upvotes: 19