summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/tools/third_party/websockets/example/legacy/unix_server.py
blob: 335039c351ca6cd1d82353487760a628f615c5d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env python

# WS server example listening on a Unix socket

import asyncio
import os.path
import websockets

async def hello(websocket):
    name = await websocket.recv()
    print(f"<<< {name}")

    greeting = f"Hello {name}!"

    await websocket.send(greeting)
    print(f">>> {greeting}")

async def main():
    socket_path = os.path.join(os.path.dirname(__file__), "socket")
    async with websockets.unix_serve(hello, socket_path):
        await asyncio.Future()  # run forever

asyncio.run(main())