Sample code for 30+ languages & platforms
Chilkat2-Python

Duplicate a Socket Wrapper Sharing the Connection

See more Socket/SSL/TLS Examples

Demonstrates Socket.DupSocket, which populates a destination Socket with another wrapper that shares this object's underlying connection.

Background. The shared connection is reference-counted, and all wrappers operate on the same live connection. The destination first releases any connection it previously held.

Chilkat Chilkat2-Python Downloads

Chilkat2-Python
import sys
import chilkat2

success = False

socket = chilkat2.Socket()

# Connect to the server using TLS.
bTls = True
maxWaitMs = 5000
success = socket.Connect("example.com",5000,bTls,maxWaitMs)
if (success == False):
    print(socket.LastErrorText)
    sys.exit()

# Create a second Socket wrapper that shares this object's underlying connection.  Both wrappers
# operate on the same live connection; the shared connection is reference-counted.
dupSock = chilkat2.Socket()
success = socket.DupSocket(dupSock)
if (success == False):
    print(socket.LastErrorText)
    sys.exit()

print("Duplicate socket wrapper created.")