此代碼的偉大工程:爲什麼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