title: How do I implement a custom protocol in Twisted?
body: <p>I'm trying to implement a simple ZeroMQ socket server as a twisted protocol, my code is currently:</p>
  
  <pre><code># Setup
  context = zmq.Context()
  socket = context.socket(zmq.PULL)
  socket.bind("tcp://127.0.0.1:5558")
  poller = zmq.Poller()
  poller.register(socket, zmq.POLLIN)
  
  # Respond to incoming messages.
  while True:
      if poller.poll(1000):
          msg = self.socket.recv()
          print "Received a message ..."
      else:
          time.sleep(0.05)
  </code></pre>
  
  <p>and I found:</p>
  
  <p><a href="http://twistedmatrix.com/documents/11.0.0/api/twisted.internet.interfaces.IProtocol.html" rel="nofollow">http://twistedmatrix.com/documents/11.0.0/api/twisted.internet.interfaces.IProtocol.html</a></p>
  
  <p>but honestly can't make sense of it. Where should I be putting the code for setup, and code for receiving data?</p>