import asyncio import json from websockets import connect import httpx async def test(): print("=== Test v3 Simple ===") async with httpx.AsyncClient() as client: r = await client.post('http://localhost:3030/auth/login', json={'username': 'admin', 'password': 'admin'}) token = r.json()['token'] async with connect('ws://localhost:3030/ws/chat') as ws: await ws.send(json.dumps({'token': token})) await ws.recv() # init await ws.send(json.dumps({'type': 'create_session', 'name': 't'})) created = json.loads(await ws.recv()) sid = created['session_id'] await ws.send(json.dumps({'type': 'connect_session', 'session_id': sid})) await ws.recv() # connected print("Enviando mensaje...") await ws.send(json.dumps({'type': 'message', 'content': 'di OK'})) # Esperar respuesta con mucho timeout print("Esperando (30s)...") try: for i in range(30): try: msg = await asyncio.wait_for(ws.recv(), timeout=1.0) print(f"RECIBIDO: {msg}") except asyncio.TimeoutError: print(f" {i+1}s...", end="\r") except Exception as e: print(f"Error: {e}") asyncio.run(test())