Results 1 to 4 of 4

Thread: Winsock and the Internet

  1. #1
    Guest
    Is there a way to download a file off the internet using the winsock control? I can do it with the inet control but i dont really like that one alot because its hard to show the progress of the download.

  2. #2
    Lively Member
    Join Date
    Nov 1999
    Location
    Melbourne, Victoria, Australia
    Posts
    126
    Add a winsock control to you form and a text box and use some code such as...

    Winsock = SckSocket
    Text = DownloadText
    Text = FilenameText
    Timer = DownloadTimer


    'These go into Declarations on the form
    Dim TotalBytes as Long
    Dim TempBytes as Long
    Dim DownloadSpeed as Integer

    'Being main code
    Private Sub Form_Load()
    DownloadSpeed = 0
    TempBytes = 0
    TotalBytes = 0
    DownloadText.Text = ""
    DownloadTimer.Enabled = False
    DownloadTimer.Interval = 1000
    End Sub

    Private Sub ConnectCmd_Click()
    SckSocket.connect "www.webserver.com", 80
    Me.Caption = "Connecting to host..."
    End Sub

    Private Sub SckSocket_Connect()
    Me.Caption = "Connected to: " & SckSocket.RemoteHostIP
    SckSocket.SendData "GET /" & FileNameTxt.Text & " HTTP/1.0" & vbcrlf & vbcrlf
    DownloadTimer.Enabled = True
    End Sub

    Private Sub SckSocket_DataArrival(bytes as long)
    TempBytes = bytes
    TotalBytes = TotalBytes + Int(bytes)
    Me.Caption = "Downloading: " & TotalBytes " bytes complete. Speed: " & DownloadSpeed
    SckSocket.GetData TempStr, VbString
    DownloadText.Text = DownloadText.Text & VbString
    End Sub

    Private Sub SckSocket_Close()
    Me.Caption = "Download Complete! " & TotalBytes & " were downloaded."
    End Sub

    Private Sub DownloadTimer_Timer()
    DownloadSpeed = Int(TempBytes / 1024)
    End Sub


    Make a form, add the above objects, run it
    and put in the Text box for "FileNameText" something like..

    /index.html

    Note: That code was off the top of my head and has NOT been tested. Perhaps someone else can repost the code so that it supports Binary files and not just a html/text file.
    Regards,

    Paul Rivoli
    ---------------------
    [email protected]
    http://members.dingoblue.net.au/~privoli

  3. #3
    Guest
    yea it seems to work, but the data is not encoded, meaning it doesn't show the content, rather just the bits or bytes or some kinda crap in there, it works fine, but how would you go about transfering a whole file from internet to your harddrive?

  4. #4
    Guest
    How can i get the size of the file before downloading it? So i can use a progressbar

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width