Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loListenSock
LOCAL loConnectedSock
LOCAL loSocketSet

lnSuccess = 0

loListenSock = CreateObject('Chilkat.Socket')

lnSuccess = loListenSock.BindAndListen(5000,25)
IF (lnSuccess = 0) THEN
    ? loListenSock.LastErrorText
    RELEASE loListenSock
    CANCEL
ENDIF

loConnectedSock = CreateObject('Chilkat.Socket')
lnSuccess = loListenSock.AcceptNext(20000,loConnectedSock)
IF (lnSuccess = 0) THEN
    ? loListenSock.LastErrorText
    RELEASE loListenSock
    RELEASE loConnectedSock
    CANCEL
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.
loSocketSet = CreateObject('Chilkat.Socket')
lnSuccess = loSocketSet.TakeSocket(loConnectedSock)
IF (lnSuccess = 0) THEN
    ? loSocketSet.LastErrorText
    RELEASE loListenSock
    RELEASE loConnectedSock
    RELEASE loSocketSet
    CANCEL
ENDIF

? "Connection added to the socket set."

RELEASE loListenSock
RELEASE loConnectedSock
RELEASE loSocketSet