Delphi DLL
Delphi DLL
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 DLL Downloads
var
success: Boolean;
socket: HCkSocket;
bTls: Boolean;
maxWaitMs: Integer;
bd: HCkBinData;
begin
success := False;
socket := CkSocket_Create();
// Connect to the server using TLS.
bTls := True;
maxWaitMs := 5000;
success := CkSocket_Connect(socket,'example.com',5000,bTls,maxWaitMs);
if (success = False) then
begin
Memo1.Lines.Add(CkSocket__lastErrorText(socket));
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 := CkBinData_Create();
success := CkSocket_ReceiveUntilByteBd(socket,10,bd);
if (success = False) then
begin
Memo1.Lines.Add(CkSocket__lastErrorText(socket));
Exit;
end;
Memo1.Lines.Add('Received ' + IntToStr(CkBinData_getNumBytes(bd)) + ' bytes (including the delimiter).');
CkSocket_Dispose(socket);
CkBinData_Dispose(bd);