세 쌍의 메서드
FastAPI 의 WebSocket 객체가 매칭된 send/receive 쌍 세 개 줘: send_text/receive_text (string), send_json/receive_json (auto-serialized JSON dict), send_bytes/receive_bytes (raw binary). receive_json() 이 parse 해주고; send_json() 이 stringify 해줘. application 의 95% 는 JSON 쌍만 써.
iter_text 와 iter_json
수동 while True loop 대신 FastAPI 가 async iterator 노출: async for msg in websocket.iter_json():. 깔끔하고 동작 같아. iterator 가 disconnect 시 멈춰 (iter form 엔 WebSocketDisconnect 처리 필요 없음).
send_json 은 format 안 정해
send_json(obj) 가 json.dumps(obj) 가 만들 걸 보내. type/data envelope 안 강제. 그건 네 일이야 — Track 5 가 protocol 설계 다뤄.