Sample code for 30+ languages & platforms
PowerBuilder

Receive a Block of Bytes to a File

See more Socket/SSL/TLS Examples

Demonstrates Socket.ReceiveBytesToFile, which receives one available block of bytes and appends it to a file.

The file path is relative to the application's current working directory. An absolute path may also be used. Supply the path appropriate to your own environment.

Background. Any buffered data is written first; otherwise a single receive operation is performed. The method appends, so repeated calls accumulate received blocks in the file.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Socket
integer li_BTls
integer li_MaxWaitMs

li_Success = 0

loo_Socket = create oleobject
li_rc = loo_Socket.ConnectToNewObject("Chilkat.Socket")
if li_rc < 0 then
    destroy loo_Socket
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  Connect to the server using TLS.
li_BTls = 1
li_MaxWaitMs = 5000
li_Success = loo_Socket.Connect("example.com",5000,li_BTls,li_MaxWaitMs)
if li_Success = 0 then
    Write-Debug loo_Socket.LastErrorText
    destroy loo_Socket
    return
end if

//  The file path is relative to the application's current working directory.  An absolute path
//  may also be used.  Supply the path appropriate to your own environment.

//  Receive one available block of bytes and append it to a file.  If bytes are already buffered,
//  they are used first; otherwise a single receive operation is performed.
li_Success = loo_Socket.ReceiveBytesToFile("qa_output/received.dat")
if li_Success = 0 then
    Write-Debug loo_Socket.LastErrorText
    destroy loo_Socket
    return
end if

Write-Debug "Received block appended to the file."


destroy loo_Socket