Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Getting "NSURLErrorDomain error 1" while connecting WebSocket

I am trying to connect WebSocket using URLSessionWebSocketTask for a Safari Web Extension,

And I have added receive function for getting messages, like this

        webSocketTask.receive { result in
            switch result {
            case .failure(let error):
                print("Failed to receive message: \(error.localizedDescription)")
            case .success(let message):
            .
            .
            and the rest of the code...


And I am getting error.localizedDescription like this:

"The operation couldn’t be completed. (NSURLErrorDomain error 1.)".


My URL for socket connection is like this (myconnection is placeholder here for actual value, as I can't share it here):

wss://127.0.0.1:10001" + "/myconnection" 

This looks like a very generic message on failure.

Can anyone help me find out what this "error 1" code means?

MacBook Pro 16″, macOS 13.4

Posted on Apr 18, 2024 7:02 AM

Reply
2 replies

Apr 18, 2024 7:55 AM in response to abhinav_dobhal

Documented codes:


URL Loading System error codes | Apple Developer Documentation


Numeric NSURLErrorDomain codes are in NSURLError.h


Your web socket connection error (-1) is the infinitely helpful “NSURLErrorUnknown”.


Check the server logs for the incoming connection, as a starting point.


And test with some other (known-working) web service server, if this server might not be stable.

Getting "NSURLErrorDomain error 1" while connecting WebSocket

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.