4 ms·
Building an Echo Server Using Tornado
- rackerhacker 17y agoTornados are dangerous, but I'm glad you're eager to serve their echos.
- tzury 17y agothis is a nice joke. wondering why do hackers vote that down
- acangiano 17y agoEcho 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 17y agoExactly, 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.
- deleted 17y ago[deleted]
- tzury 17y agoYet, it is just nice seeing how tornado can be re-used outside the core web development.
- mcav 17y agoEcho Server in Eventlet (http://eventlet.net/ 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)
- antirez 17y agoEcho 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.