Sample code for 30+ languages & platforms
Visual Basic 6.0

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 Visual Basic 6.0 Downloads

Visual Basic 6.0
Dim success As Long
success = 0

Dim socket As New ChilkatSocket

'  Connect to the server using TLS.
Dim bTls As Long
bTls = 1
Dim maxWaitMs As Long
maxWaitMs = 5000
success = socket.Connect("example.com",5000,bTls,maxWaitMs)
If (success = 0) Then
    Debug.Print socket.LastErrorText
    Exit Sub
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.
success = socket.ReceiveBytesToFile("qa_output/received.dat")
If (success = 0) Then
    Debug.Print socket.LastErrorText
    Exit Sub
End If

Debug.Print "Received block appended to the file."