Unicode C
Unicode C
Receive Bytes into a BinData
See more Socket/SSL/TLS Examples
Demonstrates Socket.ReceiveBd, which receives one delivery of binary data and appends it to a BinData. It returns whatever is immediately available.
Background. The BinData receive methods accumulate raw bytes in a BinData object. A single receive returns only what is currently available, whereas the counted receive waits for an exact number of bytes.
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;
}
// Receive one delivery of binary data and append it to a BinData. ReceiveBd returns whatever is
// immediately available; it does not loop to drain everything that may follow.
bd = CkBinDataW_Create();
success = CkSocketW_ReceiveBd(socket,bd);
if (success == FALSE) {
wprintf(L"%s\n",CkSocketW_lastErrorText(socket));
CkSocketW_Dispose(socket);
CkBinDataW_Dispose(bd);
return;
}
wprintf(L"Received %d bytes.\n",CkBinDataW_getNumBytes(bd));
CkSocketW_Dispose(socket);
CkBinDataW_Dispose(bd);
}