Skip to content

Instantly share code, notes, and snippets.

@porterjamesj
Last active August 29, 2015 14:08
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 porterjamesj/667e9e7e670b8c2730ea to your computer and use it in GitHub Desktop.
Save porterjamesj/667e9e7e670b8c2730ea to your computer and use it in GitHub Desktop.
tiny echo server with asyncio
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