Unicode C
Unicode C
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 Unicode C Downloads
#include <C_CkSocketW.h>
#include <C_CkBinDataW.h>
void ChilkatSample(void)
{
BOOL success;
HCkSocketW socket;
BOOL bTls;
int maxWaitMs;
HCkBinDataW bd;
success = FALSE;
socket = CkSocketW_Create();
// Connect to the server using TLS.
bTls = TRUE;
maxWaitMs = 5000;
success = CkSocketW_Connect(socket,L"example.com",5000,bTls,maxWaitMs);
if (success == FALSE) {
wprintf(L"%s\n",CkSocketW_lastErrorText(socket));
CkSocketW_Dispose(socket);
return;
}
// 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 = CkBinDataW_Create();
success = CkSocketW_ReceiveUntilByteBd(socket,10,bd);
if (success == FALSE) {
wprintf(L"%s\n",CkSocketW_lastErrorText(socket));
CkSocketW_Dispose(socket);
CkBinDataW_Dispose(bd);
return;
}
wprintf(L"Received %d bytes (including the delimiter).\n",CkBinDataW_getNumBytes(bd));
CkSocketW_Dispose(socket);
CkBinDataW_Dispose(bd);
}