Date: 02-16-2022
Return to Index
created by gbSnippets
'Downloading a large or small file is essentially the same code - except that with a
'large file multiple TCP Recv commands are needed. This can be handled in a simple
'Do loop, ending the loop when no more data is received (or when an error is received).
'For a small file, where the file size is less than the buffer size, no Do loop is needed.
'Primary Code:
'This example shows only the basics - open a connection, send the request,
'receive the data, and close the connection.
Tcp Open "HTTP" AT "www.garybeene.com" AS #1 TIMEOUT 60000
Tcp Print #1, "GET /files/tcp_test.txt HTTP/1.0"
Tcp Print #1, ""
Tcp Recv #1, 4096, Buffer$
Tcp Close #1
'Compilable Example: (Jose Includes)
' Client TCP/IP example - retrieve a web page
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg as Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 50,10,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
Local Buffer$
Tcp Open "HTTP" AT "www.garybeene.com" AS #1 TIMEOUT 60000
Tcp Print #1, "GET http://www.garybeene.com/files/tcp_test.txt HTTP/1.0"
Tcp Print #1, ""
Tcp Recv #1, 4096, Buffer$
Tcp Close #1
MsgBox Buffer$
End If
End Function
'gbs_00372
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm