Last active
August 29, 2015 14:08
-
-
Save porterjamesj/667e9e7e670b8c2730ea to your computer and use it in GitHub Desktop.
tiny echo server with asyncio
This file contains 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
import asyncio | |
@asyncio.coroutine | |
def server_callback(reader, writer): | |
while True: | |
data = yield from reader.readline() | |
yield from asyncio.sleep(1) | |
writer.write(data) | |
yield from writer.drain() | |
coro = asyncio.start_server(server_callback, 'localhost', 7000) | |
loop = asyncio.get_event_loop() | |
server = loop.run_until_complete(coro) | |
loop.run_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment