Sample code for 30+ languages & platforms
Delphi ActiveX

Receive Bytes up to a Delimiter into a BinData

See more Socket/SSL/TLS Examples

Demonstrates Socket.ReceiveUntilByteBd, which reads bytes until a delimiter byte is encountered and appends all bytes up to and including the delimiter to a BinData.

Background. The delimiter is a raw byte value from 0 through 255. This is useful for framing schemes that terminate each message with a known delimiter byte.

Chilkat Delphi ActiveX Downloads

Delphi ActiveX
var
success: Integer;
socket: TChilkatSocket;
bTls: Integer;
maxWaitMs: Integer;
bd: TChilkatBinData;

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;

//  Read bytes until the delimiter byte is encountered, appending all bytes up to and including the
//  delimiter to a BinData.  The delimiter is a raw byte value from 0 through 255 (here the linefeed
//  byte, decimal 10).
bd := TChilkatBinData.Create(Self);
success := socket.ReceiveUntilByteBd(10,bd.ControlInterface);
if (success = 0) then
  begin
    Memo1.Lines.Add(socket.LastErrorText);
    Exit;
  end;
Memo1.Lines.Add('Received ' + IntToStr(bd.NumBytes) + ' bytes (including the delimiter).');