zmq.error.ZMQError:没有这样的设备

时间:2015-04-03 18:15:57

标签: python-2.7 pyzmq

我的程序中出现此错误:

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

这是我为重现它而做的一个简单的脚本:

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)

我想订阅一个点并能够发送到另一个点。可能吗? 2个不同的终点。 A发送到B,B发送给C.

1 个答案:

答案 0 :(得分:2)

尝试将localhost替换为127.0.0.1

有关详细信息,请查看此stackoverflow thread