axTLS library [client: testing, debugging, documenting]

The client port is coming along. It needs to be stabilized. If I wait for the initial return response and then close the connection, the process is pretty clean. However, if I leave the connection open and the server closes the connection, it sends the Photon into a tail spin (communication loop; one red flash, etc) – it will disconnect from the cloud and go in circles… see quoted text below.

I am not quite sure how to keep the network stack stable? Is the network stack sensitive?

I’d take suggestions on ways to make the code better or questions.

Should I work towards getting the response expected and close the connection before the server disconnects? It would seem that I should be able to detect the remote closure and keep things sane? @ScruffR, can you point me in the right direction or give me some areas to investigate and/or avoid.

EDIT: May need to review this post for ideas.

For those that would like to try and work with the client and send suggestions, that would be great. The repo working towards a stable port is:

https://github.com/jr3cermak/particle/libraries/axtls

0000003186 [axtls] INFO: web></body></html>
0000003698 [comm.sparkprotocol] INFO: Sending A describe message
0000003698 [comm.sparkprotocol] WARN: received ERROR CoAPMessage
0000003698 [system] WARN: Communication loop error, closing cloud socket
0000003800 [system] INFO: Cloud: connecting
0000003800 [system] INFO: Read Server Address = type:1,domain:device.spark.io
0000003815 [system] INFO: Resolved host device.spark.io to 54.90.239.114
0000003831 [system] INFO: connected to cloud 54.90.239.114:5683
0000003831 [system] INFO: Cloud socket connected
0000003831 [system] INFO: Starting handshake: presense_announce=1
0000003831 [comm.sparkprotocol.handshake] INFO: Started: Receive nonce
0000003863 [comm.sparkprotocol.handshake] INFO: Encrypting handshake nonce
0000003864 [comm.sparkprotocol.handshake] ERROR: RSA encrypt error -1087
0000003864 [system] WARN: Cloud handshake failed, code=-1087
0000004115 [system] INFO: Cloud: disconnecting
0000004115 [system] INFO: Cloud: disconnected
0000004923 [system] INFO: Cloud: connecting
0000004923 [system] INFO: Read Server Address = type:1,domain:device.spark.io
0000004952 [system] INFO: Resolved host device.spark.io to 54.90.239.114
0000004969 [system] INFO: connected to cloud 54.90.239.114:5683
0000004969 [system] INFO: Cloud socket connected
0000004969 [system] INFO: Starting handshake: presense_announce=1
0000004970 [comm.sparkprotocol.handshake] INFO: Started: Receive nonce
0000004995 [comm.sparkprotocol.handshake] INFO: Encrypting handshake nonce
0000004995 [comm.sparkprotocol.handshake] ERROR: RSA encrypt error -1087
0000004996 [system] WARN: Cloud handshake failed, code=-1087
0000005246 [system] INFO: Cloud: disconnecting
0000005246 [system] INFO: Cloud: disconnected
0000006054 [system] INFO: Cloud: connecting
0000006054 [system] INFO: Read Server Address = type:1,domain:device.spark.io
0000006093 [system] INFO: Resolved host device.spark.io to 54.90.239.114
0000006124 [system] INFO: connected to cloud 54.90.239.114:5683
0000006124 [system] INFO: Cloud socket connected
0000006125 [system] INFO: Starting handshake: presense_announce=1
0000006125 [comm.sparkprotocol.handshake] INFO: Started: Receive nonce
0000006156 [comm.sparkprotocol.handshake] INFO: Encrypting handshake nonce
0000006156 [comm.sparkprotocol.handshake] ERROR: RSA encrypt error -1087
0000006157 [system] WARN: Cloud handshake failed, code=-1087