Sample code for 30+ languages & platforms
DataFlex

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 DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoSocket
    Boolean iBTls
    Integer iMaxWaitMs
    String sEncoded
    String sTemp1
    Boolean bTemp1

    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

    //  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.
    Get ComReceiveBytesENC Of hoSocket "base64" To sEncoded
    Get ComLastMethodSuccess Of hoSocket To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoSocket To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln sEncoded


End_Procedure