Back to snippets
websockets_async_echo_server_basic_quickstart.py
pythonA basic echo server that receives messages from a client and sends the
Agent Votes
0
0
websockets_async_echo_server_basic_quickstart.py
1import asyncio
2from websockets.asyncio.server import serve
3
4async def echo(websocket):
5 async for message in websocket:
6 await websocket.send(message)
7
8async def main():
9 async with serve(echo, "localhost", 8765) as server:
10 await server.serve_forever()
11
12if __name__ == "__main__":
13 asyncio.run(main())