surveyor respondent pattern in nanomsg in python

廉价感情. 提交于 2020-01-16 00:46:17

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!