O'Reilly logo

Learning Python Network Programming by Sam Washington, Dr. M. O. Faruque Sarker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a custom SSL client/server

So far, we have been dealing more with the SSL or TLS client. Now, let us have a look at the server side briefly. As you are already familiar with the TCP/UDP socket server creation process, let's skip that part and just concentrate on the SSL wrapping part. The following code snippet shows an example of a simple SSL server:

import socket import ssl SSL_SERVER_PORT = 8000 if __name__ == '__main__': server_socket = socket.socket() server_socket.bind(('', SSL_SERVER_PORT)) server_socket.listen(5) print("Waiting for ssl client on port %s" %SSL_SERVER_PORT) newsocket, fromaddr = server_socket.accept() # Generate your server's public certificate and private key pairs. ssl_conn = ssl.wrap_socket(newsocket, server_side=True, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required