Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cError:Optional(Error Domain=kCFErrorDomainCFNetwork Code=1 "(null)" UserInfo={_kCFStreamErrorCodeKey=1, _kCFStreamErrorDomainKey=12}) #458

Closed
yusufonderd opened this issue May 7, 2018 · 10 comments

Comments

@yusufonderd
Copy link

I'm trying to connect aws signed url.

let webSocketUrl = "a2xxxxxxxx.iot.us-east-1.amazonaws.com/mqtt?..."
var  transport = MQTTCFSocketTransport()
transport.host = webSocketUrl
transport.port = 443;
 let session = MQTTSession()
 session?.transport = transport;
 session?.connect(connectHandler: { (error) in
        print("error:\(error)")
 })                

I give an exception :

cError:Optional(Error Domain=kCFErrorDomainCFNetwork Code=1 "(null)" UserInfo={_kCFStreamErrorCodeKey=1, _kCFStreamErrorDomainKey=12})

@nathanmrtns
Copy link

nathanmrtns commented May 8, 2018

@yusufonderd try this:

        let transport: MQTTWebsocketTransport = MQTTWebsocketTransport()
        transport.host = "a2xxxxxxxx.iot.us-east-1.amazonaws.com"
        transport.path = "/mqtt?..."
        transport.port = 443
        transport.tls = true
        session.transport = transport
        session.userName = "your-username"
        session.password = "your-password"
        session.protocolLevel = .version311
        session.clientId = String(ProcessInfo().processIdentifier)
        session.connect() 

@yusufonderd
Copy link
Author

MQTTCFSocketTransport object has not 'path' properties.

@nathanmrtns
Copy link

@yusufonderd updated the answer with the right transport

@yusufonderd
Copy link
Author

@nathanmrtns Now I'm getting two different error when change tls value :

When transport.tls = true : Error Domain=SRWebSocketErrorDomain Code=2132 "received bad response code from server 403" UserInfo={NSLocalizedDescription=received bad response code from server 403, HTTPResponseStatusCode=403}

When transport.tls = false : Error Domain=MQTT Code=-8 "Server has closed connection without connack." UserInfo={NSLocalizedDescription=Server has closed connection without connack.}

@nathanmrtns
Copy link

@yusufonderd do you need a certificate to connect?

@yusufonderd
Copy link
Author

yusufonderd commented May 8, 2018

No I'm using generated URL. This url already authorized. Not need a certificate.

@nathanmrtns
Copy link

nathanmrtns commented May 8, 2018

@yusufonderd I'm not sure, but I believe you have to change your AWS host config.

Check this issues and see if it helps #120 and #433

@yusufonderd
Copy link
Author

Hi @nathanmrtns I see this log in xcode when connect socket :

MQTTSessionLegacy connectToHost:xxxxxxx.iot.us-east-1.amazonaws.com port:443 usingSSL:1 connectHandler:0x0
[MQTTSession] connectWithConnectHandler:0x0
[MQTTSession] connecting
[MQTTCFSocketTransport] open
[MQTTCFSocketEncoder] setState 0/0
[MQTTCFSocketDecoder] NSStreamEventOpenCompleted
[MQTTCFSocketEncoder] NSStreamEventOpenCompleted
[MQTTCFSocketEncoder] NSStreamEventHasSpaceAvailable
[MQTTCFSocketEncoder] setState 0/1
[MQTTSession] mqttTransportDidOpen
[MQTTSession] sending CONNECT
[MQTTMessage] wireFormat(39)=<10250006 4d514973 64700302 003c0017 496e646f 6f725472 696f5365 7344656e 656d6532 393139>...
[MQTTSession] mqttTransport send
[MQTTCFSocketEncoder] buffer to write (39)=<10250006 4d514973 64700302 003c0017 496e646f 6f725472 696f5365 7344656e 656d6532 393139>...
[MQTTCFSocketEncoder] NSStreamEventHasSpaceAvailable

Do you have any idea ?

@jcavar
Copy link
Contributor

jcavar commented May 9, 2018

Hi @yusufonderd. As @nathanmrtns pointed, please check #433 to work with signed url. You will need to subclass MQTTWebsocketTransport

@jcavar
Copy link
Contributor

jcavar commented May 11, 2018

Tracked in #433

@jcavar jcavar closed this as completed May 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants