Runtime enable disable of TLSSocket

Hello,

I am using TLSSocket for secure socket communication and its working fine. For that i have to decide either to use TLSSocket or TCPSocket at a compile time.
But my requirement is to enable or disable TLS at a runtime. So is there any way to do this stuff.
Thanks in advance.

Depending on what you mean by this, there are a few ways:

  1. Create the appropriate socket type (TCPSocket vs TLSSocket) either with new or similar. At this point, you know a TCPSocket will not have security enabled. Any further calls to either socket could be done with a Socket pointer and will still use the correct method for the class.
  2. If you do not know which one it will be ahead of time for some reason, but want to determine whether it is a TLSSocket or a TCPSocket, I believe you can call getsockopt(NSAPI_TLSSOCKET_LEVEL, NSAPI_TLSSOCKET_ENABLE, boolean_pointer, size_pointer). I am fairly certain this gets set in a secure socket. I know it sets the boolean pointer to a 0.

I am not sure if this answers your question, however. You will need to be a little more specific if not.