title: ZeroMQ: how to keep a connection of PAIR/PAIR between python and node?
body: <p>I have a python server and a node.js client. The problem is that at times when I restart my node.js script it does not reconnect.</p>
  <p>Also, what I don't understand is why is there an infinite loop on python. Can't I use events to listen for connections.</p>
  <p>Below is the server and client.</p>
  <hr />
  <pre><code>context = zmq.Context()
  socket = context.socket(zmq.PAIR)
  print(&quot;Binding socket to port: &quot; + str(port))
  socket.bind(&quot;tcp://*:%s&quot; % port)
  print(&quot;Connection has been established&quot;)
  while True: // cant we listen for events here i.e on connection etc
      msg = socket.recv()
      print(msg)
      socket.send(&quot;Server response&quot;)
  </code></pre>
  <hr />
  <pre><code>'use strict';
  var globevt  = require('../lib/emitter');
  var sprintf  = require(&quot;sprintf-js&quot;).sprintf;
  var logger   = require('../lib/logat');
  var zmq      = require('zeromq')
      , socket = zmq.socket('pair');
  const fs     = require('fs');
  
  socket.connect('tcp://127.0.0.1:3000');
  socket.on('message', function (msg) {
      console.log(msg);
  });
  </code></pre>
  <p>Also this only works if the server starts first then the client. How can I make the client to re-try until it connects?</p>