Sample code for 30+ languages & platforms
Lianja

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

Lianja
llSuccess = .F.

loListenSock = createobject("CkSocket")

llSuccess = loListenSock.BindAndListen(5000,25)
if (llSuccess = .F.) then
    ? loListenSock.LastErrorText
    release loListenSock
    return
endif

loConnectedSock = createobject("CkSocket")
llSuccess = loListenSock.AcceptNext(20000,loConnectedSock)
if (llSuccess = .F.) then
    ? loListenSock.LastErrorText
    release loListenSock
    release loConnectedSock
    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.
loSocketSet = createobject("CkSocket")
llSuccess = loSocketSet.TakeSocket(loConnectedSock)
if (llSuccess = .F.) then
    ? loSocketSet.LastErrorText
    release loListenSock
    release loConnectedSock
    release loSocketSet
    return
endif

? "Connection added to the socket set."


release loListenSock
release loConnectedSock
release loSocketSet