You have probably come across the discussion around secure web communication using SSL, or more precisely TLS, which is adopted by many other high-level protocols. Let's see how we can wrap a plain sockets connection with SSL. Python has a built-in SSL module that serves this purpose.
In the following example, we would like to create a plain TCP socket and connect to an HTTPS-enabled web server. We can establish that connection using the SSL module and check the various properties of the connection. For example, to check the identity of the remote web server, we can see whether the hostname is the same in the SSL certificate, as we expect it to be. The following is an example of a secure socket-based client.