What is WebSocket? URLSessionWebSocketTask
Essence
WebSocket is a two-way communication protocol over a single TCP connection. The client starts with an ordinary HTTP request carrying Upgrade: websocket; after a 101 Switching Protocols response the connection becomes a full-duplex channel: both sides send messages (text or binary frames) at any time, with no new requests or headers. Schemes are ws:// and wss:// (over TLS; ATS requires wss).
Uses: chats, price tickers, live updates, collaborative editing, game lobbies — anything where the server must push data. For one-way notifications SSE (bytes(for:)) is often enough; for rare events, APNs.
The rest of this answer, with code and interview follow-ups, is in the DevPrep app.
Read the full answer in DevPrep