I found some “strange” phenomena when using Python for network programming.
After constructing the SSL context and obtaining the SSL socket, the original socket will be automatically closed. Why is this? Is there any need to do this?
Just like the following code:
main.py
ssl_ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
fd = socket.socket()
ssl_fd = ssl_ctx.wrap_socket(fd, server_hostname='www.baidu.com')
print(fd)
The output of this code is as follows:
E:Projects_library_py>python main.py
<socket.socket [closed] fd=-1, family=2, type=1, proto=0>