WebSocketRequest Development Started

Alamofire has started development of a WebSocketRequest type on the feature/websocket-request branch. WebSocketRequest wraps URLSessionWebSocketTask to provide websocket functionality using Alamofire APIs. We'd like to avoid the mistakes made during DataStreamRequest's developer and start gathering use cases, desired API, and feature requests before fully building out the feature.

Fundamentally, WebSocketRequest won't be too different than DataStreamRequest, with closure handlers that are called as data is received. The biggest difference, obviously, is the ability to send messages back along the socket.

So we're asking the community to tell use your dream websocket features by providing examples of your use, problems you encounter with other websocket libraries or URLSessionWebSocketTask, and features you wish those other libraries had.

This wrapper has made good progress and should now be usable to receive URLSessionWebSocketTask.Message values, as well as sending messages to the server.

A note of caution: URLSessionWebSocketTask seems to have a regression in at least iOS 14.5 / macOS 11.4 where messages received just before a close frame from the server will be dropped. If you control the server, adding a delay before the close frame can workaround the issue. I've found 60ms to be sufficient for local server on a virtualized machine. You should test will real devices for an appropriate delay.

1 Like
Terms of Service

Privacy Policy

Cookie Policy