Xbase++
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oListenSock
LOCAL oConnectedSock
LOCAL oSocketSet
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 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.
oSocketSet := CreateObject("Chilkat.Socket")
nSuccess := oSocketSet:TakeSocket(oConnectedSock)
IF (nSuccess == 0)
? oSocketSet:LastErrorText
oListenSock:destroy()
oConnectedSock:destroy()
oSocketSet:destroy()
RETURN
ENDIF
? "Connection added to the socket set."
oListenSock:destroy()
oConnectedSock:destroy()
oSocketSet:destroy()