DataFlex
DataFlex
Send Encoded Bytes over a Socket
See more Socket/SSL/TLS Examples
Demonstrates Socket.SendBytesENC, which decodes text using a named encoding (such as base64) and sends the resulting binary bytes.
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoSocket
Boolean iBTls
Integer iMaxWaitMs
String sTemp1
Move False To iSuccess
Get Create (RefClass(cComChilkatSocket)) To hoSocket
If (Not(IsComObjectCreated(hoSocket))) Begin
Send CreateComObject of hoSocket
End
// Connect to the server using TLS.
Move True To iBTls
Move 5000 To iMaxWaitMs
Get ComConnect Of hoSocket "example.com" 5000 iBTls iMaxWaitMs To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSocket To sTemp1
Showln sTemp1
Procedure_Return
End
// Decode the text using the named encoding, then send the resulting binary bytes. Here the base64
// text "SGVsbG8=" decodes to the bytes for "Hello".
Get ComSendBytesENC Of hoSocket "SGVsbG8=" "base64" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSocket To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "Bytes sent."
End_Procedure