Created
September 25, 2020 09:41
-
-
Save Integralist/752e8620783d7507af9130e1954cf6f7 to your computer and use it in GitHub Desktop.
[Asyncio built-in Socket Server] #python #python3 #asyncio #server #socket #web #http
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 | |
async def handle_request(reader, writer): | |
writer.write("hello world".encode()) # needs to be bytes not string | |
writer.close() | |
async def main(): | |
srv = await asyncio.start_server(handle_request, '127.0.0.1', 8081) | |
async with srv: | |
await srv.serve_forever() | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment