Skip to content

Instantly share code, notes, and snippets.

@Integralist
Created September 25, 2020 09:41
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 Integralist/752e8620783d7507af9130e1954cf6f7 to your computer and use it in GitHub Desktop.
Save Integralist/752e8620783d7507af9130e1954cf6f7 to your computer and use it in GitHub Desktop.
[Asyncio built-in Socket Server] #python #python3 #asyncio #server #socket #web #http
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