Skip to content

Instantly share code, notes, and snippets.

@ax003d
Created August 13, 2015 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ax003d/57d438cd9ef191695ef3 to your computer and use it in GitHub Desktop.
Save ax003d/57d438cd9ef191695ef3 to your computer and use it in GitHub Desktop.
tornado echo server
from tornado.tcpserver import TCPServer
from tornado.ioloop import IOLoop
from uuid import uuid4
class EchoConnection(object):
def __init__(self, stream, address):
self.address = address
self.stream = stream
self.read()
def read(self):
self.stream.read_until('\r\n', self.on_read)
def on_read(self, data):
self.stream.write(data)
self.read()
class EchoTCPServer(TCPServer):
def handle_stream(self, stream, address):
EchoConnection(stream, address)
if __name__=="__main__":
server = EchoTCPServer()
server.listen(8000)
IOLoop.instance().start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment