Click to See Complete Forum and Search --> : Samples Of Winsock
SteveCRM
Apr 11th, 2000, 04:22 AM
I have not gotten winsock to work! Can someone send me an example of a small program that has some comments?
privoli
Apr 11th, 2000, 01:41 PM
A sameple winsock application. Connets to a webserver and downloads a .html file...
Create a new form...
Add a text box caled "Text1"
Add a command button called "Command1"
Add a winsock control called "Winsock1"
Set Text1 to MultiLine = True and ScrollBars = Both
Paste the following code and run....
Private Sub Command1_Clik()
'connect to server on port 80
Winsock1.connect "www.vb-world.net", 80
End Sub
Private Sub Winsock1_Connect()
'send http request (ask for the file)
Winsock1.senddata "GET /index.html HTTP/1.0" & vbclrf & vbcrlf
'you must send two vbcrlf's when using HTTP
End Sub
Private Sub Winsock1_DataArrival(bytes as long)
'weve recieved a packet, keep track of it and add it to the text box
Winsock1.getdata TempStr, vbString
text1.text = text1.text & TempStr
End Sub
Private Sub Winsock1_Close()
'its complete, the httpd server automatically closes the connection
'when the file get is complete :)
msgbox "Download complete."
End Sub
Nitro
Apr 12th, 2000, 06:21 AM
Paul!
Is this the method to download a zip file?
privoli
Apr 12th, 2000, 12:25 PM
You can use that code for any file you want...However for a binary file such as a .zip or .exe you will need to store all the bytes into an array then dump the bytes into a file....
Putting the bytes into a textbox for a binary file (.zip or .exe etc..) will not work, you will need to put it in a byte array instead....
Search around the place for some code that stores a string into a byte arrray and dumps it to a file...
I'll try working on a file download agent later tonight...
Cheers
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.