Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loSocket
LOCAL lnBTls
LOCAL lnMaxWaitMs
LOCAL loBd

lnSuccess = 0

loSocket = CreateObject('Chilkat.Socket')

*  Connect to the server using TLS.
lnBTls = 1
lnMaxWaitMs = 5000
lnSuccess = loSocket.Connect("example.com",5000,lnBTls,lnMaxWaitMs)
IF (lnSuccess = 0) THEN
    ? loSocket.LastErrorText
    RELEASE loSocket
    CANCEL
ENDIF

*  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.
loBd = CreateObject('Chilkat.BinData')
lnSuccess = loSocket.ReceiveBd(loBd)
IF (lnSuccess = 0) THEN
    ? loSocket.LastErrorText
    RELEASE loSocket
    RELEASE loBd
    CANCEL
ENDIF

? "Received " + STR(loBd.NumBytes) + " bytes."

RELEASE loSocket
RELEASE loBd