I am trying to connect to a socket using a url, which I can confirm connects successfully when using a socket connect tool, but when I try using URLSessionWebSocketTask it fails with the error:
Note: have had to replace url domain and endpoint with *example.com/endpoint` for work reasons
... NSLocalizedDescription=A server with the specified hostname could not be found.}
FAIL: Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found." UserInfo={NSErrorFailingURLStringKey=https://example.com/endpoint, NSLocalizedDescription=A server with the specified hostname could not be found., NSErrorFailingURLKey=https://example.com/endpoint}
The url I provide starts with the wss
prefix:
let socketUrl = "wss://example.com/endpoint"
...
webSocketTask = urlSession.webSocketTask(with: socketUrl)
webSocketTask?.resume()
but the error posted earlier indicates that the task is trying to connect using https
instead (which the server does not support).
I don't remember having to setup anything last time, but it has been about a year since working with these things. Have I missed something setup or app transport security settings etc?