Sample code for 30+ languages & platforms
Delphi ActiveX

Duplicate a Socket Wrapper Sharing the Connection

See more Socket/SSL/TLS Examples

Demonstrates Socket.DupSocket, which populates a destination Socket with another wrapper that shares this object's underlying connection.

Background. The shared connection is reference-counted, and all wrappers operate on the same live connection. The destination first releases any connection it previously held.

Chilkat Delphi ActiveX Downloads

Delphi ActiveX
var
success: Integer;
socket: TChilkatSocket;
bTls: Integer;
maxWaitMs: Integer;
dupSock: TChilkatSocket;

begin
success := 0;

socket := TChilkatSocket.Create(Self);

//  Connect to the server using TLS.
bTls := 1;
maxWaitMs := 5000;
success := socket.Connect('example.com',5000,bTls,maxWaitMs);
if (success = 0) then
  begin
    Memo1.Lines.Add(socket.LastErrorText);
    Exit;
  end;

//  Create a second Socket wrapper that shares this object's underlying connection.  Both wrappers
//  operate on the same live connection; the shared connection is reference-counted.
dupSock := TChilkatSocket.Create(Self);
success := socket.DupSocket(dupSock.ControlInterface);
if (success = 0) then
  begin
    Memo1.Lines.Add(socket.LastErrorText);
    Exit;
  end;
Memo1.Lines.Add('Duplicate socket wrapper created.');