From 3f599293da43720b6cc20f3770a7a62d0a8ee5ea Mon Sep 17 00:00:00 2001 From: shanghui Date: Wed, 6 Dec 2017 14:45:21 +0800 Subject: [PATCH] =?utf8?q?Make=20the=20example=20code=20in=20the=20documen?= =?utf8?q?t=20"tornado.ioloop=20=E2=80=94=20Main=20event=20loop"=20can=20c?= =?utf8?q?opy-paste-run=20directly.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- tornado/ioloop.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tornado/ioloop.py b/tornado/ioloop.py index c950a89d3..ea9261294 100644 --- a/tornado/ioloop.py +++ b/tornado/ioloop.py @@ -89,9 +89,18 @@ class IOLoop(Configurable): import errno import functools - import tornado.ioloop import socket + import tornado.ioloop + from tornado import gen + from tornado.iostream import IOStream + + @gen.coroutine + def handle_connection(connection, address): + stream = IOStream(connection) + message = yield stream.read_until_close() + print("message from client:", message.decode().strip()) + def connection_ready(sock, fd, events): while True: try: @@ -107,7 +116,7 @@ class IOLoop(Configurable): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.setblocking(0) - sock.bind(("", port)) + sock.bind(("", 8888)) sock.listen(128) io_loop = tornado.ioloop.IOLoop.current() -- 2.47.2