Debian Codegraph @

testing/web-platform/tests/tools/third_party/websockets/example/legacy/unix_server.py

raw
1 #!/usr/bin/env python
2
3 # WS server example listening on a Unix socket
4
5 import asyncio
6 import os.path
7 import websockets
8
9 async def hello(websocket):
10 name = await websocket.recv()
11 print(f"<<< {name}")
12
13 greeting = f"Hello {name}!"
14
15 await websocket.send(greeting)
16 print(f">>> {greeting}")
17
18 async def main():
19 socket_path = os.path.join(os.path.dirname(__file__), "socket")
20 async with websockets.unix_serve(hello, socket_path):
21 await asyncio.Future() # run forever
22
23 asyncio.run(main())