Delphi ActiveX
Delphi ActiveX
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 Delphi ActiveX Downloads
var
success: Integer;
listenSock: TChilkatSocket;
connectedSock: TChilkatSocket;
socketSet: TChilkatSocket;
begin
success := 0;
listenSock := TChilkatSocket.Create(Self);
success := listenSock.BindAndListen(5000,25);
if (success = 0) then
begin
Memo1.Lines.Add(listenSock.LastErrorText);
Exit;
end;
connectedSock := TChilkatSocket.Create(Self);
success := listenSock.AcceptNext(20000,connectedSock.ControlInterface);
if (success = 0) then
begin
Memo1.Lines.Add(listenSock.LastErrorText);
Exit;
end;
// 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.
socketSet := TChilkatSocket.Create(Self);
success := socketSet.TakeSocket(connectedSock.ControlInterface);
if (success = 0) then
begin
Memo1.Lines.Add(socketSet.LastErrorText);
Exit;
end;
Memo1.Lines.Add('Connection added to the socket set.');