12.4 · WebSockets, multipart and large transfers, and network path monitoring
Beyond request and response: a connection that stays open, bodies too large for memory, and a network that comes and goes.
Mental model. Three different shapes of traffic: a conversation (WebSocket), a parcel (upload or download) and the road itself (path monitoring).
Connections that stay open
WebSockets with <code>URLSessionWebSocketTask</code>.
- How does URLSessionWebSocketTask work, and what do you have to handle yourself?
A WebSocket is a long-lived, bidirectional connection that starts as an HTTP request (an upgrade) and then carries framed text or binary messages both ways…
Big bodies and bad networks
Multipart uploads, progress, and <code>NWPathMonitor</code>.
- How do you do multipart uploads, large uploads and downloads, and show progress?
Multipart form data sends several parts (fields and files) in one request with Content-Type: multipart/form-data; boundary=B. The body is plain text framing… - Why use NWPathMonitor instead of reachability, and how do you use connectivity information correctly?
Old reachability (SCNetworkReachability and third-party wrappers) answered “is there a route to a host?” and encouraged a bad pattern: check, then decide…
More in Networking
- 12.1 · Sessions, configurations, tasks, delegates and background transfers
- 12.2 · HTTP versions, TLS, App Transport Security and certificate pinning
- 12.3 · Pagination, caching and conditional requests, and authentication refresh
- 12.5 · Retries, backoff, idempotency and cancellation
- 12.6 · REST, GraphQL and gRPC, and building a client platform
- 12.7 · Image loading pipelines: download, decode, downsample, cache
- 12.8 · Building URLs, reading headers, classifying errors and timeouts
- 12.9 · Single-flight token refresh, streaming lines, multipart bodies and request signing
- 12.10 · Network.framework, background sessions, delegates versus async, diagnosing and measuring