SendHTTPData() and ReceiveHTTPData() function

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

SendHTTPData() and ReceiveHTTPData() function

Post by Kukulkan »

Hi there,

After many discussions of people who like to send data or files using the network functions, I recommend some additional functions:

SendHTTPData(ContentPointer.l, ContentLength.l)
and
ReceiveHTTPData(ResultPointer.l {, TimeoutSeconds.l))

The feature of this functions will be the usage of HTTP to ensure the complete transfer.

Internally, this function will create a HTTP-type of message:

Code: Select all

Content-Length: 438
Content-Type: application/zip;
Content-Transfer-Encoding: base64

[Data begins here...]
The corresponding ReceiveHTTPData() function may parse this information and ensures complete transfer until returning to normal program flow.

Code: Select all

; sending:
Content.s = "Hi, this is the message to transfer"
SendHTTPData(@Content.s, Len(Content.s)

; receiving
Size.l = ReceiveHTTPData(0)
If Size.l > 0
  Content.s = Space(Size.l)
  Success.l = ReceiveHTTPData(@Content.s, 60)
EndIf
The ReceiveHTTPData() function will work in two ways. The first call with a pointer 0 will return the needed size for retrieving the data (header information). A call with a valid pointer starts the receiving process. The optional TimeoutSeconds parameter will give better control about cancelled connections or other failure.

Just an idea...

Kukulkan