B4X
B4X
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 B4X Downloads
Dim success As Boolean = False
Dim socket As ChilkatSocket
socket.Initialize("socket")
' Connect to the server using TLS.
Dim bTls As Boolean = True
Dim maxWaitMs As Int = 5000
success = socket.Connect("example.com", 5000, bTls, maxWaitMs)
If success = False Then
Log(socket.LastErrorText)
Return
End If
' 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.
Dim dupSock As ChilkatSocket
dupSock.Initialize("dupSock")
success = socket.DupSocket(dupSock)
If success = False Then
Log(socket.LastErrorText)
Return
End If
Log("Duplicate socket wrapper created.")