[zeromq-dev] How to tell from an exception thrown by recv_string() if this exception is for the listening socket or for the client socket?

Yuri yuri at rawbw.com
Fri Oct 7 21:56:02 CEST 2022


I have a question about this hypothetical situation.


The code below can throw a variety of exceptions.

For example, the listening socket can fail for some reason, or read from 
the client socket can fail for some reason.

I am interested in how to differentiate between errors for the listening 
socket and errors for the client socket.


---begin code---

import zmq
import time
import sys

context = zmq.Context()
socket = context.socket(zmq.REP)
socket.setsockopt(zmq.RCVTIMEO, 5000)

socket.bind("tcp://*:%s" % 5556)

while True:

     try:

         message = socket.recv_string() # line that can throw an exception

     except Exception:

         print("Exception occurred")

---end code---



Yuri




More information about the zeromq-dev mailing list