title: Streaming video using pyzmq
body: <p>I am using the Python bindings for zmq to send messages both between processes and across a network.  So far, no problem.  I now have an application where I want to stream data recovered from a small camera on a Raspberry Pi.  I have no issues actually recording the data but now I want to be able to stream that data.  I have an example on how to do this using the low level <code>sockets</code> api but would really like to use <code>zmq</code> for this application.</p>
  
  <p>The <code>picamera</code> <a href="https://picamera.readthedocs.io/en/release-1.10/recipes1.html#recording-to-a-network-stream" rel="nofollow">documentation</a> has the example below on how to use a network stream to send data:</p>
  
  <pre><code>import socket
  import time
  import picamera
  
  # Connect a client socket to my_server:8000 (change my_server to the
  # hostname of your server)
  client_socket = socket.socket()
  client_socket.connect(('my_server', 8000))
  
  # Make a file-like object out of the connection
  connection = client_socket.makefile('wb')
  try:
      with picamera.PiCamera() as camera:
          camera.resolution = (640, 480)
          camera.framerate = 24
          # Start a preview and let the camera warm up for 2 seconds
          camera.start_preview()
          time.sleep(2)
          # Start recording, sending the output to the connection for 60
          # seconds, then stop
          camera.start_recording(connection, format='h264')
          camera.wait_recording(60)
          camera.stop_recording()
  finally:
      connection.close()
      client_socket.close()
  </code></pre>
  
  <p><code>zmq</code> does not implement a <code>buffer</code> interface, so you can not simply change the <code>socket</code> object for a <code>zmq.Context()</code> object.  I feel like this should be relatively simple, but have been unable to find any information on this.  Does anyone have any suggestions on how to use the <code>zmq</code> api in this case?</p>