PowerBuilder
PowerBuilder
Move a Connection into a Socket Set
See more Socket/SSL/TLS Examples
Demonstrates Socket.TakeSocket, which moves a connection into a newly created member of this object's socket set. After one or more calls, the object acts as a set of sockets.
Background. A socket set groups multiple connections so they can be monitored together with the SelectForReading and SelectForWriting methods. After success, the source socket holds no connection.
Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_ListenSock
oleobject loo_ConnectedSock
oleobject loo_SocketSet
li_Success = 0
loo_ListenSock = create oleobject
li_rc = loo_ListenSock.ConnectToNewObject("Chilkat.Socket")
if li_rc < 0 then
destroy loo_ListenSock
MessageBox("Error","Connecting to COM object failed")
return
end if
li_Success = loo_ListenSock.BindAndListen(5000,25)
if li_Success = 0 then
Write-Debug loo_ListenSock.LastErrorText
destroy loo_ListenSock
return
end if
loo_ConnectedSock = create oleobject
li_rc = loo_ConnectedSock.ConnectToNewObject("Chilkat.Socket")
li_Success = loo_ListenSock.AcceptNext(20000,loo_ConnectedSock)
if li_Success = 0 then
Write-Debug loo_ListenSock.LastErrorText
destroy loo_ListenSock
destroy loo_ConnectedSock
return
end if
// Move the connection out of connectedSock and into a newly created member of this object's socket
// set. After one or more such calls, socketSet acts as a set of connected sockets (useful with the
// SelectForReading / SelectForWriting methods). After success, connectedSock holds no connection.
loo_SocketSet = create oleobject
li_rc = loo_SocketSet.ConnectToNewObject("Chilkat.Socket")
li_Success = loo_SocketSet.TakeSocket(loo_ConnectedSock)
if li_Success = 0 then
Write-Debug loo_SocketSet.LastErrorText
destroy loo_ListenSock
destroy loo_ConnectedSock
destroy loo_SocketSet
return
end if
Write-Debug "Connection added to the socket set."
destroy loo_ListenSock
destroy loo_ConnectedSock
destroy loo_SocketSet