novastone-media / MQTT-Client-Framework

iOS, macOS, tvOS native ObjectiveC MQTT Client Framework
Other
1.84k stars 466 forks source link

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

Closed yusufonderd closed 6 years ago

yusufonderd commented 6 years ago

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 commented 6 years ago

@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 commented 6 years ago

MQTTCFSocketTransport object has not 'path' properties.

nathanmrtns commented 6 years ago

@yusufonderd updated the answer with the right transport

yusufonderd commented 6 years ago

@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 commented 6 years ago

@yusufonderd do you need a certificate to connect?

yusufonderd commented 6 years ago

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

nathanmrtns commented 6 years ago

@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 commented 6 years ago

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 commented 6 years ago

Hi @yusufonderd. As @NathanMrtns pointed, please check https://github.com/novastone-media/MQTT-Client-Framework/issues/433 to work with signed url. You will need to subclass MQTTWebsocketTransport

jcavar commented 6 years ago

Tracked in #433