Xbase++
Xbase++
Move a Connection into Another Socket
See more Socket/SSL/TLS Examples
Demonstrates Socket.TakeConnection, which moves the active connection from one Socket into another. The receiving object first releases any connection it previously held.
Background. Unlike TakeSocket, TakeConnection does not add a member to a socket set. After success, the source socket holds no connection. This is useful for handing an accepted connection to a dedicated handler object.
Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oListenSock
LOCAL oConnectedSock
LOCAL oHandlerSock
nSuccess := 0
oListenSock := CreateObject("Chilkat.Socket")
nSuccess := oListenSock:BindAndListen(5000, 25)
IF (nSuccess == 0)
? oListenSock:LastErrorText
oListenSock:destroy()
RETURN
ENDIF
oConnectedSock := CreateObject("Chilkat.Socket")
nSuccess := oListenSock:AcceptNext(20000, oConnectedSock)
IF (nSuccess == 0)
? oListenSock:LastErrorText
oListenSock:destroy()
oConnectedSock:destroy()
RETURN
ENDIF
// Move the active connection out of connectedSock and into another Socket object. Unlike
// TakeSocket, this does not add a member to a socket set. After success, connectedSock holds no
// connection.
oHandlerSock := CreateObject("Chilkat.Socket")
nSuccess := oHandlerSock:TakeConnection(oConnectedSock)
IF (nSuccess == 0)
? oHandlerSock:LastErrorText
oListenSock:destroy()
oConnectedSock:destroy()
oHandlerSock:destroy()
RETURN
ENDIF
? "Connection moved to the handler socket."
oListenSock:destroy()
oConnectedSock:destroy()
oHandlerSock:destroy()