asyncio server python

Solutions on MaxInterview for asyncio server python by the best coders in the world

showing results for - "asyncio server python"
Tommaso
24 Nov 2018
1import asyncio, socket
2
3async def handle_client(reader, writer):
4    request = None
5    while request != 'quit':
6        request = (await reader.read(255)).decode('utf8')
7        response = str(eval(request)) + '\n'
8        writer.write(response.encode('utf8'))
9        await writer.drain()
10    writer.close()
11
12async def run_server():
13    server = await asyncio.start_server(handle_client, 'localhost', 15555)
14    async with server:
15        await server.serve_forever()
16
17asyncio.run(run_server())