Created
August 13, 2015 10:20
-
-
Save ax003d/57d438cd9ef191695ef3 to your computer and use it in GitHub Desktop.
tornado echo server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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