Xbase++ Requires Chilkat v11.0.0+
Xbase++
Example: Socket.DupSocket method
See more Socket/SSL/TLS Examples
Demonstrates how to call the DupSocket method.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oSocket
LOCAL oSocket_for_sending
LOCAL oSocket_for_monitor
nSuccess := 0
oSocket := CreateObject("Chilkat.Socket")
nSuccess := oSocket:Connect("example.com", 443, 1, 5000)
// ...
// ...
// Duplicate the socket to share the same connection across threads.
// In a multithreaded application, each thread should use its own socket object. For example:
// - The main thread can use the original socket for reading.
// - A secondary thread can use a duplicate for writing.
// - Another thread can use a separate duplicate to monitor the connection status.
oSocket_for_sending := CreateObject("Chilkat.Socket")
nSuccess := oSocket:DupSocket(oSocket_for_sending)
IF (nSuccess == 0)
? oSocket:LastErrorText
oSocket:destroy()
oSocket_for_sending:destroy()
RETURN
ENDIF
oSocket_for_monitor := CreateObject("Chilkat.Socket")
nSuccess := oSocket:DupSocket(oSocket_for_monitor)
IF (nSuccess == 0)
? oSocket:LastErrorText
oSocket:destroy()
oSocket_for_sending:destroy()
oSocket_for_monitor:destroy()
RETURN
ENDIF
// All three socket objects: socket, socket_for_sending, and socket_for_monitor share the same underlying connection.
oSocket:destroy()
oSocket_for_sending:destroy()
oSocket_for_monitor:destroy()