此代码的伟大工程:为什么zeromq不能在localhost上运行?
import zmq, json, time
def main():
context = zmq.Context()
subscriber = context.socket(zmq.SUB)
subscriber.bind("ipc://test")
subscriber.setsockopt(zmq.SUBSCRIBE, '')
while True:
print subscriber.recv()
def main():
context = zmq.Context()
publisher = context.socket(zmq.PUB)
publisher.connect("ipc://test")
while True:
publisher.send("hello world")
time.sleep(1)
但这个代码不 *工作:
import zmq, json, time
def recv():
context = zmq.Context()
subscriber = context.socket(zmq.SUB)
subscriber.bind("tcp://localhost:5555")
subscriber.setsockopt(zmq.SUBSCRIBE, '')
while True:
print subscriber.recv()
def send():
context = zmq.Context()
publisher = context.socket(zmq.PUB)
publisher.connect("tcp://localhost:5555")
while True:
publisher.send("hello world")
time.sleep(1)
它提出了这样的错误:
ZMQError: No such device
为什么不能zeromq使用localhost接口?
它只在同一台机器上的IPC上工作吗?
我喜欢用像127.0.0.101更高的地址,并改变它每个应用程序。比IPC插座更清洁。 – 2011-07-01 01:39:03
@fdb是的,这解决了问题,但并不能解释为什么!它需要[更多解释](http://stackoverflow.com/a/8958414/462302)。 – aculich 2012-01-22 02:12:49