Download app.py from Starchik1/serv: direct link, hf CLI and curl.
- Browser
- Download file 755 Bytes
-
https://huggingface.co/spaces/Starchik1/serv/resolve/main/app.py
- Command line
-
hf download hf://spaces/Starchik1/serv/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Starchik1/serv/resolve/main/app.py
755 Bytes
| import asyncio | |
| import websockets | |
| clients = set() | |
| async def handler(websocket, path): | |
| clients.add(websocket) | |
| try: | |
| while True: | |
| data = await websocket.recv() | |
| if data: | |
| # Рассылаем полученные данные всем подключенным клиентам | |
| await asyncio.wait([client.send(data) for client in clients]) | |
| except websockets.exceptions.ConnectionClosed: | |
| pass | |
| finally: | |
| clients.remove(websocket) | |
| async def main(): | |
| server = await websockets.serve(handler, "0.0.0.0", 12345) | |
| print("WebSocket сервер запущен на порту 12345") | |
| await server.wait_closed() | |
| if __name__ == "__main__": | |
| asyncio.run(main()) | |