Sample code for 30+ languages & platforms
DataFlex

Send BinData Contents over a Socket

See more Socket/SSL/TLS Examples

Demonstrates Socket.SendBd, which sends bytes from a BinData beginning at an offset. A numBytes of 0 sends from the offset through the end of the data.

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

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoSocket
    Boolean iBTls
    Integer iMaxWaitMs
    Variant vBd
    Handle hoBd
    String sTemp1
    Integer iTemp1

    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

    //  Place some bytes into a BinData to be sent.
    Get Create (RefClass(cComChilkatBinData)) To hoBd
    If (Not(IsComObjectCreated(hoBd))) Begin
        Send CreateComObject of hoBd
    End
    Get ComAppendString Of hoBd "message payload" "utf-8" To iSuccess

    //  Send bytes from the BinData starting at the given offset.  A numBytes of 0 sends from the offset
    //  through the end of the data.
    Get pvComObject of hoBd to vBd
    Get ComSendBd Of hoSocket vBd 0 0 To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoSocket To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComNumBytes Of hoBd To iTemp1
    Showln "Sent " iTemp1 " bytes."


End_Procedure