first commit

first commit
This commit is contained in:
mher 2025-06-28 13:01:18 +03:30
commit 57ebfdc618

31
websocketserver.py Normal file
View File

@ -0,0 +1,31 @@
import asyncio
import websockets
import datetime
clients = set()
async def handler(websocket):
print(f"[{datetime.datetime.now()}] New client connected: {websocket.remote_address}")
clients.add(websocket)
try:
async for message in websocket:
print(f"[{datetime.datetime.now()}] Received voice packet: {len(message)} bytes")
dead_clients = set()
for client in list(clients):
if client != websocket:
try:
await client.send(message)
except websockets.exceptions.ConnectionClosed:
dead_clients.add(client)
clients.difference_update(dead_clients)
except websockets.exceptions.ConnectionClosed:
print(f"[{datetime.datetime.now()}] Client disconnected: {websocket.remote_address}")
finally:
clients.discard(websocket)
async def main():
print("\nVoice WebSocket server running on ws://192.168.100.5:8765")
async with websockets.serve(handler, "192.168.31.10", 8765):
await asyncio.Future()
asyncio.run(main())