Daily iOS
Networking

WebSocket connection management

You've got a bug report that the chat app's WebSocket connection drops often and the app is slow to notice. How would you detect a dropped connection promptly on iOS?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

TCP doesn't tell you the peer is gone, so put an app-level heartbeat on top of URLSessionWebSocketTask: periodic pings with a pong timeout to catch silent drops.

Share a question