1

我正在尝试编写测量员受访者模式。但它会抛出错误:

nanomsg.NanoMsgAPIError:在此状态下无法执行操作

from nanomsg import *

s1 = Socket(SURVEYOR)
s1.bind('ipc://bob')
s1.send(b'hello nanomsg')
print(s1.recv())
s1.close()

from nanomsg import *

s2 = Socket(RESPONDENT)
s2.connect('ipc://bob')
print(s2.recv())
s2.send(b'Hello')
s2.close()

如何在 python 中实现这种模式?

4

1 回答 1

0

它是一个错误,可以通过在绑定或连接语句之后插入“time.sleep(0.1)”来规避。

from nanomsg import *
import time


s1 = Socket(SURVEYOR)
s1.bind('ipc://bob.ipc')
time.sleep(0.1)
s1.send(b'hello nanomsg')
print(s1.recv())
s1.close()
于 2015-06-26T12:03:14.697 回答