title: Echoing messages received through UDP back through a different TCP port
body: <p>I use Python 2.7.x (2.7.8) and am trying to write a program using twisted python to function like this:</p>
  
  <ul>
  <li>Program waits for a messaged received through TCP 7001 or UDP 7000.</li>
  <li>Messages received through UDP 7000 are bridged over to TCP 7001 going out.</li>
  </ul>
  
  <p>I couldn't figure out how to bridge UDP to TCP, so I looked up an example on this site, like this one, <a href="https://stackoverflow.com/questions/20008281/twisted-udp-to-tcp-bridge">Twisted UDP to TCP Bridge</a> but the problem is that the example is lying because it doesn't work. I added a "print datagram" on datagramReceived to see if UDP responds to receiving <strong>anything at all</strong> and it does not. This is totally frustrating.</p>
  
  <p>Here's my current test code altered <strong>a little bit</strong> from that example:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>from twisted.internet.protocol import Protocol, Factory, DatagramProtocol
  from twisted.internet import reactor
  
  class TCPServer(Protocol):
      def connectionMade(self):
          self.port = reactor.listenUDP(7000, UDPServer(self))
  
      def connectionLost(self, reason):
          self.port.stopListening()
  
      def dataReceived(self, data):
          print "Server said:", data
  
  
  class UDPServer(DatagramProtocol):
      def __init__(self, stream):
          self.stream = stream
  
      def datagramReceived(self, datagram, address):
          print datagram
          self.stream.transport.write(datagram)
  
  
  def main():
      f = Factory()
      f.protocol = TCPServer
      reactor.listenTCP(7001, f)
      reactor.run()
  
  if __name__ == '__main__':
      main()</code></pre>
  </div>
  </div>
  </p>
  
  <p>As you can see I changed the ports to comply with my test environment and added a print datagram to see if anything calls datagramReceived. I have no problems sending TCP things to this program, TCPServer works just fine because dataReceived can be called.</p>