Swift
Swift
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 Swift Downloads
func chilkatTest() {
var success: Bool = false
let socket = CkoSocket()!
// Connect to the server using TLS.
var bTls: Bool = true
var maxWaitMs: Int = 5000
success = socket.connect(hostname: "example.com", port: 5000, ssl: bTls, maxWaitMs: maxWaitMs)
if success == false {
print("\(socket.lastErrorText!)")
return
}
// 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.
let dupSock = CkoSocket()!
success = socket.dup(dest: dupSock)
if success == false {
print("\(socket.lastErrorText!)")
return
}
print("Duplicate socket wrapper created.")
}