Unicode C
Unicode C
Receive Bytes as Encoded Text from a Socket
See more Socket/SSL/TLS Examples
Demonstrates Socket.ReceiveBytesENC, which receives one delivery of binary data and returns it encoded as text using a named encoding.
Background. The ENC methods move raw binary data to and from printable text using a named encoding such as
base64 or hex, which is convenient for logging or for handling binary data as strings.Chilkat Unicode C Downloads
#include <C_CkSocketW.h>
void ChilkatSample(void)
{
BOOL success;
HCkSocketW socket;
BOOL bTls;
int maxWaitMs;
const wchar_t *encoded;
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 return it encoded as text using the named encoding. This
// is convenient for logging or transporting binary data as printable text.
encoded = CkSocketW_receiveBytesENC(socket,L"base64");
if (CkSocketW_getLastMethodSuccess(socket) == FALSE) {
wprintf(L"%s\n",CkSocketW_lastErrorText(socket));
CkSocketW_Dispose(socket);
return;
}
wprintf(L"%s\n",encoded);
CkSocketW_Dispose(socket);
}