Sample code for 30+ languages & platforms
PowerBuilder

Example: Socket.DupSocket method

See more Socket/SSL/TLS Examples

Demonstrates how to call the DupSocket method.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Socket
oleobject loo_Socket_for_sending
oleobject loo_Socket_for_monitor

li_Success = 0

loo_Socket = create oleobject
li_rc = loo_Socket.ConnectToNewObject("Chilkat.Socket")
if li_rc < 0 then
    destroy loo_Socket
    MessageBox("Error","Connecting to COM object failed")
    return
end if
li_Success = loo_Socket.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.

loo_Socket_for_sending = create oleobject
li_rc = loo_Socket_for_sending.ConnectToNewObject("Chilkat.Socket")

li_Success = loo_Socket.DupSocket(loo_Socket_for_sending)
if li_Success = 0 then
    Write-Debug loo_Socket.LastErrorText
    destroy loo_Socket
    destroy loo_Socket_for_sending
    return
end if

loo_Socket_for_monitor = create oleobject
li_rc = loo_Socket_for_monitor.ConnectToNewObject("Chilkat.Socket")

li_Success = loo_Socket.DupSocket(loo_Socket_for_monitor)
if li_Success = 0 then
    Write-Debug loo_Socket.LastErrorText
    destroy loo_Socket
    destroy loo_Socket_for_sending
    destroy loo_Socket_for_monitor
    return
end if

// All three socket objects: socket, socket_for_sending, and socket_for_monitor share the same underlying connection.


destroy loo_Socket
destroy loo_Socket_for_sending
destroy loo_Socket_for_monitor