问题
I am trying to write a surveyor respondent pattern. But it throws the error:
nanomsg.NanoMsgAPIError: Operation cannot be performed in this state
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()
How can I implement this pattern in python?
回答1:
Its a bug, it can be circumvented by inserting "time.sleep(0.1)", after the bind or connect statement.
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()
来源:https://stackoverflow.com/questions/31071644/surveyor-respondent-pattern-in-nanomsg-in-python