Reputation: 321
I'm using the following code to fetch the frames from the client :
def fetch_frame(self):
context = zmq.Context()
footage_socket = context.socket(zmq.REP)
footage_socket.bind('tcp://*:5555')
while True:
frame = footage_socket.recv_string()
frame = frame.encode()
img = base64.b64decode(frame)
npimg = np.fromstring(img, dtype=np.uint8)
source = cv2.imdecode(npimg, 1)
Unfortunately, it is throwing the following error :
zmq.error.ZMQError: Operation cannot be accomplished in current state
What is the proper way to retrieve image using zmq?
UPDATE:
Following is the traceback :
File "/home/receive/main.py", line 77, in <module>
main()
File "/home/receive/main.py", line 73, in main
ci.fetch_frame()
File "/home/receive/main.py", line 59, in fetch_frame
frame = footage_socket.recv_string()
File "/home/.local/lib/python3.8/site-packages/zmq/sugar/socket.py", line 608, in recv_string
msg = self.recv(flags=flags)
File "zmq/backend/cython/socket.pyx", line 791, in zmq.backend.cython.socket.Socket.recv
File "zmq/backend/cython/socket.pyx", line 827, in zmq.backend.cython.socket.Socket.recv
File "zmq/backend/cython/socket.pyx", line 191, in zmq.backend.cython.socket._recv_copy
File "zmq/backend/cython/socket.pyx", line 186, in zmq.backend.cython.socket._recv_copy
File "zmq/backend/cython/checkrc.pxd", line 26, in zmq.backend.cython.checkrc._check_rc
zmq.error.ZMQError: Operation cannot be accomplished in current state
Upvotes: 0
Views: 342
Reputation: 1
Q : "
ZMQError: Operation cannot be accomplished in current state
"
The core reason is, that your code violated ZeroMQ REQ/REP
documented properties.
Asking REP
-instance to .send()
-ed message before a REQ
-instance has already "asked" its counterparty first, the API has to throw such error.
Similarly, if trying to .recv()
a message on the REQ
-side, before it has first "asked" by a .send()
the REP
-side ( to reply ), the API has to throw such error.
In a case no other interaction is needed, a PUSH/PULL
Scalable Formal Communication Pattern Archetype, where PUSH
-side will .send()
& the PULL
-side will .recv()
, is IMHO the best way ahead.
You might like to read more tips and links about this in this.
Upvotes: 1