Xbase++
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oSocket
LOCAL nBTls
LOCAL nMaxWaitMs
LOCAL oBd
nSuccess := 0
oSocket := CreateObject("Chilkat.Socket")
// Connect to the server using TLS.
nBTls := 1
nMaxWaitMs := 5000
nSuccess := oSocket:Connect("example.com", 5000, nBTls, nMaxWaitMs)
IF (nSuccess == 0)
? oSocket:LastErrorText
oSocket:destroy()
RETURN
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.
oBd := CreateObject("Chilkat.BinData")
nSuccess := oSocket:ReceiveBd(oBd)
IF (nSuccess == 0)
? oSocket:LastErrorText
oSocket:destroy()
oBd:destroy()
RETURN
ENDIF
? "Received " + Str(oBd:NumBytes) + " bytes."
oSocket:destroy()
oBd:destroy()