2015-06-26 65 views
1

我正在嘗試寫一個測量員響應者模式。但它拋出的錯誤:測量員被調查者在nanomsg中的模式python

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() 

我怎樣才能在Python中實現這種模式?

回答

0

它是一個bug,它可以通過在bind或connect語句後插入「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() 
相關問題