17 lines
471 B
Python
17 lines
471 B
Python
from websockets import *
|
|
import asyncio, json
|
|
|
|
async def test(websocket: ServerConnection) -> None:
|
|
message: str = await websocket.recv()
|
|
print(f"Server received: {message}")
|
|
response: str = f"Hello {websocket.id}. You sent {message}"
|
|
await websocket.send(response)
|
|
print(f"Server replied: {response}")
|
|
|
|
async def main() -> None:
|
|
async with serve(test, "", 8765):
|
|
await asyncio.Future()
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|