Debian Codegraph @

testing/web-platform/tests/tools/third_party/websockets/example/quickstart/server.py

raw
1 #!/usr/bin/env python
2
3 import asyncio
4 import websockets
5
6 async def hello(websocket):
7 name = await websocket.recv()
8 print(f"<<< {name}")
9
10 greeting = f"Hello {name}!"
11
12 await websocket.send(greeting)
13 print(f">>> {greeting}")
14
15 async def main():
16 async with websockets.serve(hello, "localhost", 8765):
17 await asyncio.Future() # run forever
18
19 if __name__ == "__main__":
20 asyncio.run(main())