Delphi DLL
Delphi DLL
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 Delphi DLL Downloads
var
success: Boolean;
listenSock: HCkSocket;
connectedSock: HCkSocket;
handlerSock: HCkSocket;
begin
success := False;
listenSock := CkSocket_Create();
success := CkSocket_BindAndListen(listenSock,5000,25);
if (success = False) then
begin
Memo1.Lines.Add(CkSocket__lastErrorText(listenSock));
Exit;
end;
connectedSock := CkSocket_Create();
success := CkSocket_AcceptNext(listenSock,20000,connectedSock);
if (success = False) then
begin
Memo1.Lines.Add(CkSocket__lastErrorText(listenSock));
Exit;
end;
// 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.
handlerSock := CkSocket_Create();
success := CkSocket_TakeConnection(handlerSock,connectedSock);
if (success = False) then
begin
Memo1.Lines.Add(CkSocket__lastErrorText(handlerSock));
Exit;
end;
Memo1.Lines.Add('Connection moved to the handler socket.');
CkSocket_Dispose(listenSock);
CkSocket_Dispose(connectedSock);
CkSocket_Dispose(handlerSock);