Hello, I'm having an unusual problem dealing with web sockets from Swift. I adopted the URLSessionWebSocketDelegate for my session extension and there are times when after the webSocketTask:didOpenWithProtocol: method is called that I then get errors indicating that the web socket is not connected. This all happens in the foreground with airplane mode off, without putting my app in the background.
I get the connection errors simultaneously in 2 places:
- urlSession(_ session:task: didCompleteWithError error: )
- webSocketTask?.receive(completionHandler: @escaping (Result<URLSessionWebSocketTask.Message, Error>)
Forgive me as I have 2 rather ****** questions:
- Is the web socket open state the same as the web socket's connected state?
- If it isn't the same how do I know if a web socket is connected, using Apple's URLSessionTask extension?
Thanks. I'd rather stick with Apple's implementation and not use a third party web socket library. Pretty sure the error is mine.