aws-amplify / aws-sdk-ios

AWS SDK for iOS. For more information, see our web site:
https://aws-amplify.github.io/docs
Other
1.68k stars 885 forks source link

AWS IOT - Websocket closed with code 1005 #764

Closed shofixti244 closed 6 years ago

shofixti244 commented 6 years ago

Hello there, I'm using the AWSIoT framework in XCode 9.1, using Cocoapods to manage the dependancy. My code is written in Swift4 and being compiled onto an 11.1.1 iPhone 6+ as well as a similar 6+ simulator.

On both simulators and physical devices I am encountering an issue while trying to connect using the connectUsingWebSocket method. After making the connection call, I get a callback with the connecting status, shortly followed by another disconnect callback. During this I get the following output repeated in the log:

2017-11-17 13:58:18:694 IoTTemperatureControlSample[2458:356302] Initializing MQTTEncoder and MQTTDecoder streams 2017-11-17 13:58:18:694 IoTTemperatureControlSample[2458:356302] opening encoder stream. 2017-11-17 13:58:18:694 IoTTemperatureControlSample[2458:356302] opening decoder stream. 2017-11-17 13:58:18:694 IoTTemperatureControlSample[2458:356302] MQTTEncoderStatus = 0 2017-11-17 13:58:18:694 IoTTemperatureControlSample[2458:356302] MQTTSessionStatus = 0 2017-11-17 13:58:18:765 IoTTemperatureControlSample[2458:356090] WebSocket closed with code:1005 with reason:(null) 2017-11-17 13:58:18:765 IoTTemperatureControlSample[2458:356302] MQTT session error, code: 2 2017-11-17 13:58:18:766 IoTTemperatureControlSample[2458:356302] closing encoder stream. 2017-11-17 13:58:18:766 IoTTemperatureControlSample[2458:356302] closing decoder stream. 2017-11-17 13:58:19:769 IoTTemperatureControlSample[2458:356302] MQTT session closed. 2017-11-17 13:58:35:774 IoTTemperatureControlSample[2458:356302] Trying to reconnect to session.

This occurs in both my own code and the IoTTemperatureControlSample example.

I have ensured that my plist allows the appropriate App Transport Security entries, and I have verified that my endpoint is correct.

Any feedback or clues here would be very helpful. For the time being I find myself quite stuck.

Edit: Careful looking through the log has revealed that the first error code is different: 2017-11-17 14:09:53:461 IoTTemperatureControlSample[2469:359892] WebSocket closed with code:1001 with reason:Stream end encountered

shofixti244 commented 6 years ago

I managed to solve the issue.

For anybody else having this problem... Make sure you have a correct policy attached to your unauthenticated Cognito pool. It appears this issue was related to not having correct permissions to access AWS IoT.