Sample code for 30+ languages & platforms
PowerBuilder

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Socket
integer li_BTls
integer li_MaxWaitMs
oleobject loo_DupSock

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

//  Connect to the server using TLS.
li_BTls = 1
li_MaxWaitMs = 5000
li_Success = loo_Socket.Connect("example.com",5000,li_BTls,li_MaxWaitMs)
if li_Success = 0 then
    Write-Debug loo_Socket.LastErrorText
    destroy loo_Socket
    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.
loo_DupSock = create oleobject
li_rc = loo_DupSock.ConnectToNewObject("Chilkat.Socket")

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

Write-Debug "Duplicate socket wrapper created."


destroy loo_Socket
destroy loo_DupSock