Method Name:
bind
Method Signature:
bind()
Parameters:
None
Return Value:
None
Method Overview:
- The bind() method attaches a socket(Remember, the SSLSocket is derived from the socket class) to an available IP address and a port.
- The client programs generally do not invoke the bind() method on a socket instance. The reason is the socket will be attached to an ephemeral port when the bind() method is not called.
- The clients, contact server programs all the times. Hence, a server socket should be attached to a specific IP address and a port number.
Example:
- The Python program below when executed binds an SSLSocket to a specific port and IP.
- The client program provided in the Introduction to SSLSocket, can be used to connect to this server.
- The server responds by sending a the temperature of a city to the client.
# An example Python program that binds to an IP address and port import ssl # File paths # Socket creation # SSL context creation # To handle self-signed certificates # Load the certificate of the Certificate Authority, with which the # Load the server certificate # Create server socket # Make an SSLSocket # Bind the secure socket to a specific IP address and port number # Listen to accept connections while(True): |
Output-Server:
Replied to ('127.0.0.1', 51589) with the temperature value 60.22 |
Output-Client:
X.509 certificate of the server DemoServer: |