

Building an Echo Server Using Tornado - superjared
http://superjared.com/entry/building-echo-server-using-tornado/

======
acangiano
Echo Server in Twisted Matrix:

    
    
      from twisted.internet import protocol, reactor
    
      class Echo(protocol.Protocol):    
          def dataReceived(self, data):
              self.transport.write(data)
    
      if __name__ == '__main__':
          factory = protocol.ServerFactory()
          factory.protocol = Echo
          reactor.listenTCP(8000,factory)
          reactor.run()

~~~
clemesha
Exactly, thanks for posting this (you beat me to it).

It's not that we need to constantly respond to every Tornado post with a
Twisted rebuttal - but it is appropriate to respond to articles the contain
FUD and demonstrate far less elegant, far more verbose, non cross-platform
solutions.

------
mcav
Echo Server in Eventlet (<http://eventlet.net/>):

    
    
        from eventlet import api
    
        def handle_socket(address):
            sock, ip = address
            while True:
               sock.send(sock.recv(1))
    
        api.tcp_server(api.tcp_listener(('0.0.0.0', 6000)), handle_socket)

~~~
blasdel
You can destructure the address tuple in the arguments:

    
    
      def handle_socket((sock, ip)):
          while True:
             sock.send(sock.recv(1))

~~~
mcav
Yeah; I didn't want to confuse people who don't know that Eventlet's API
passes a tuple (they might think it sends handle_socket 2 arguments)

------
antirez
Echo server in 10-years old Tcl (more?):

    
    
        socket -server acceptConnections 9999
        proc acceptConnections {fd clientaddr clientport} {
            fconfigure $fd -blocking 0
            fileevent $fd readable [list replyToClient $fd]
        }
        proc replyToClient fd {
            set s [read $fd]
            puts -nonewline $fd $s
            flush $fd
        }
        vwait forever
    

Note that this is a multiplexing non blocking server, exactly like Twisted /
Tornado. All features built-in in the language. Tcl failed copying the obvious
missing features from other languages. Other languages are failing copying the
good things from Tcl.

p.s. note the poetry contained in the "vwait forever" statement ;) Our program
is willing to run without stop until the end of the universe.

------
rackerhacker
Tornados are dangerous, but I'm glad you're eager to serve their echos.

~~~
tzury
this is a nice joke. wondering why do hackers vote that down

