blob: d2efeb7e5303ba6c3ec5aa410381bed75e56adc9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#!/usr/bin/env python
# Server example with HTTP Basic Authentication over TLS
import asyncio
import websockets
async def hello(websocket):
greeting = f"Hello {websocket.username}!"
await websocket.send(greeting)
async def main():
async with websockets.serve(
hello, "localhost", 8765,
create_protocol=websockets.basic_auth_protocol_factory(
realm="example", credentials=("mary", "p@ssw0rd")
),
):
await asyncio.Future() # run forever
asyncio.run(main())
|