How to coreclty solve ZMQ socket error "zmq.error.ZMQError: Address in use" in python
<p><br>I am using a windows 7 machine with Python 2.7 to make a simple Client/Server ZMQ proof of concept. I ran into this scenario where the listening socket(Server side of the app) is already in use and this throws "zmq.error.ZMQError: Address in use" error. <br>How do you think is the best way to avoid this error? I was thinking of, when binding the socket catch this error and if error is thrown restart the context and the socket. This is not working, is still throws and error when binding. Server code:</p>

<pre><code>class ZMQServer:
    context = None
    socket = None

    def __init__(self, port):
        self.context = zmq.Context()
        self.socket = self.context.socket(zmq.REP)
        try:
            self.socket.bind("tcp://*:"+str(port))
        except zmq.error.ZMQError:
            print ("socket already in use, restarting")
            self.socket.close()
            self.context.destroy()
            self.context = zmq.Context()
            self.socket = self.context.socket(zmq.REP)
            self.socket.bind("tcp://*:"+str(port))
</code></pre>