title: ZeroMQ permanent PULL socket
body: <p>I’ve been using a <code>PUSH/PULL</code> pattern in an application and it works as expected except when I switch off abruptly the computer or remove the ethernet cable in the <code>PULL</code>-side.</p>
  
  <p>The <code>PUSH</code>-side keeps working with other <code>PULL</code>-sockets, but maintains switched off socket as if still were alive.</p>
  
  <p>I have modified TCP-parameters (interval, count...) without results.</p>
  
  <p>Is it possible to avoid this connection even when the host computer is switched off or the ethernet cable removed?</p>
  
  <p>EDIT:</p>
  
  <p>This is a small test i've made</p>
  
  <p>server.py</p>
  
  <pre><code>import zmq
  import time
  
  context = zmq.Context()
  socket = context.socket(zmq.PUSH)
  socket.setsockopt(zmq.RCVHWM, 1)
  socket.setsockopt(zmq.SNDHWM, 1)
  socket.setsockopt(zmq.LINGER, 0)
  socket.setsockopt(zmq.IMMEDIATE, 1)
  print(socket.sndtimeo)
  socket.sndtimeo = 0
  
  socket.setsockopt(zmq.TCP_KEEPALIVE,1)
  socket.setsockopt(zmq.TCP_KEEPALIVE_CNT,1)
  socket.setsockopt(zmq.TCP_KEEPALIVE_IDLE,1)
  socket.setsockopt(zmq.TCP_KEEPALIVE_INTVL,1)
  socket.bind('tcp://*:5555')
  count= 0
  while True:
      print('Sending', count)
      try:
          socket.send(str(count).encode('utf-8'), zmq.NOBLOCK)
          count+= 1
          print('Ok')
      except zmq.error.Again:
          print('Error')
      time.sleep(0.1)
  </code></pre>
  
  <p>client.py</p>
  
  <pre><code>import zmq
  import time
  import sys
  #from common import time_utils
  
  context = zmq.Context()
  socket = context.socket(zmq.PULL)
  server = '127.0.0.1:5555'
  try:
      server = sys.argv[1]
  except IndexError:
      pass
  socket.setsockopt(zmq.TCP_KEEPALIVE,1)
  socket.setsockopt(zmq.TCP_KEEPALIVE_CNT,1)
  socket.setsockopt(zmq.TCP_KEEPALIVE_IDLE,1)
  socket.setsockopt(zmq.TCP_KEEPALIVE_INTVL,1)
  socket.setsockopt(zmq.RCVHWM, 1)
  socket.connect(server)
  while True:
  #  Wait for next request from client
      message = socket.recv()
      print("Received request: ", message)
  </code></pre>
  
  <p>Running one instance of the server and 2 clients (one in the same machine that runs the server and one in other computer). Removing the ethernet cable of the second computer results in that the server keeps sending messages to the second client for a while.</p>
  
  <p>As you can see I have tested all <code>setsockopt</code>.</p>