Results 1 to 18 of 18

Thread: Vb6: Winsock grab full data on arrival

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    224

    Vb6: Winsock grab full data on arrival

    i have this code but it can grab only a part of the page source code, how can i make it grab the whole page source code?

    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Dim strData As String
    Winsock1.GetData strData, vbString, bytesTotal
    Text1.Text = strData
    End Sub

  2. #2
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Vb6: Winsock grab full data on arrival

    DataArrival events can occur with as little as 1 byte of data received, and at most 8192 bytes of data. You have to accumulate data until "the end" (however your protocol defines that).

    There is no magic to "suck harder" on the wire.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    224

    Re: Vb6: Winsock grab full data on arrival

    Quote Originally Posted by dilettante View Post
    DataArrival events can occur with as little as 1 byte of data received, and at most 8192 bytes of data. You have to accumulate data until "the end" (however your protocol defines that).

    There is no magic to "suck harder" on the wire.
    please give me code to test it
    thanx

  4. #4
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    733

    Re: Vb6: Winsock grab full data on arrival

    You can parse the acquired data to know the data size. Then cycle to compare the data size until it is greater than or equal to the total data

  5. #5
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: Vb6: Winsock grab full data on arrival

    To get all the data you have to get reading and storing the data until the data stream stops. It could take many reads to get it all. You have to buffer the data with each read.
    The code you have will end up showing only the last read as you are overwriting the variable each time.

    As a simple test try changing the line
    Code:
    Text1.Text = strData
    to
    Code:
    Text1.Text = Text1.Text & strData
    this should show you all the data even with multiple reads.

    Now this is not the way to handle a read, you really need a buffer var of some sort but that simple change should show you the difference.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    224

    Re: Vb6: Winsock grab full data on arrival

    Quote Originally Posted by DataMiser View Post
    To get all the data you have to get reading and storing the data until the data stream stops. It could take many reads to get it all. You have to buffer the data with each read.
    The code you have will end up showing only the last read as you are overwriting the variable each time.

    As a simple test try changing the line
    Code:
    Text1.Text = strData
    to
    Code:
    Text1.Text = Text1.Text & strData
    this should show you all the data even with multiple reads.

    Now this is not the way to handle a read, you really need a buffer var of some sort but that simple change should show you the difference.
    i already tried that, it keep getting old text + new text, i cant do that
    i need actual code to get whole page source with each time new data

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    224

    Re: Vb6: Winsock grab full data on arrival

    Quote Originally Posted by xxdoc123 View Post
    You can parse the acquired data to know the data size. Then cycle to compare the data size until it is greater than or equal to the total data
    please send me code to do it
    i dont know

  8. #8
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    733

    Re: Vb6: Winsock grab full data on arrival

    If you use winsock to download web pages. You can detect that the returned data contains the file header, which contains the size of the returned data. The cumulative return knows that it is greater than the size in the file header.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    224

    Re: Vb6: Winsock grab full data on arrival

    Quote Originally Posted by xxdoc123 View Post
    If you use winsock to download web pages. You can detect that the returned data contains the file header, which contains the size of the returned data. The cumulative return knows that it is greater than the size in the file header.
    please give me code to do it
    i am browsing a site using winsock and i need to get full page source code to textbox on data arrival event
    but i can only so far get a first page of page source only, i need to get it all

  10. #10
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Vb6: Winsock grab full data on arrival

    Asking for people to give you code is not going to get you the code most of the time. I would suggest searching this site and others for examples using WinSock and web pages.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  11. #11
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: Vb6: Winsock grab full data on arrival

    Quote Originally Posted by geekmaro View Post
    i already tried that, it keep getting old text + new text, i cant do that
    i need actual code to get whole page source with each time new data
    You have to clear the text before you try to load a new page.

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    224

    Re: Vb6: Winsock grab full data on arrival

    Quote Originally Posted by LaVolpe View Post
    Asking for people to give you code is not going to get you the code most of the time. I would suggest searching this site and others for examples using WinSock and web pages.
    i searched everywhere and i could not find the code i need, in ready to hire someone here to do the task

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    224

    Re: Vb6: Winsock grab full data on arrival

    Quote Originally Posted by DataMiser View Post
    You have to clear the text before you try to load a new page.
    tried it, didnt work
    the problem is that Winsock1.GetData has limit of data it can get
    i need to somehow grab all data, i hope i can find someone who can give me code to do it

  14. #14
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: Vb6: Winsock grab full data on arrival

    Quote Originally Posted by geekmaro View Post
    tried it, didnt work
    the problem is that Winsock1.GetData has limit of data it can get
    i need to somehow grab all data, i hope i can find someone who can give me code to do it
    Wow, if you did it right it would work. No I am not going to write it for you. Using the code I showed before you simply to to have an empty text box when you start to load the data, the data will go through in as many chunks as needed and each will append to the text in the text box. Once all the data is loaded for that page and you want to load a different one then you need to clear the text box before you start to load the next page. Very simple.

    Now if the page you are trying to load has a lot of data coming back it may be to much for a text box and you may need to use a different control than can hold more data.

    In any case the method I showed you will work if you just stop and think about it rather than begging for code it would be working already.

  15. #15
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    733

    Re: Vb6: Winsock grab full data on arrival

    Quote Originally Posted by geekmaro View Post
    tried it, didnt work
    the problem is that Winsock1.GetData has limit of data it can get
    i need to somehow grab all data, i hope i can find someone who can give me code to do it
    Text4.Text

    Connection: keep-alive
    Cache-Control: max-age=0
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
    Content-Type: application/x-www-form-urlencoded
    Referer: http://xxxx
    Accept-Encoding: deflate
    Accept-Language: xxxx,zh;q=0.8
    Code:
         flag = ""
        WinSockHttp1.Post_data = Text4.Text
        WinSockHttp1.Head_cookie = CoS
        WinSockHttp1.Successflags = "flag xxxx" ’Set a flag to determine whether all required web pages have been downloaded. Sometimes we only need part of the webpage content
        WinSockHttp1.SockHttp "http://XXX.COM,", mPOST, "1011101"
    
    Private Sub WinSockHttp1_ReturnComplete( Arraydata() As Byte, Flags As String)
        
        strWeb = WinSockHttp1.Return_webstring ‘download complete string
                                                     ‘’Arraydata is bytearrays。
        'Debug.Print index
        'raw.debug_print strweb
    
    
    End Sub
    The code logic is not very clear. Modify it yourself, I suggest you use winhttp
    Attached Files Attached Files
    Last edited by xxdoc123; Sep 16th, 2020 at 09:06 PM.

  16. #16

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    224

    Re: Vb6: Winsock grab full data on arrival

    Quote Originally Posted by xxdoc123 View Post
    Code:
         flag = ""
        WinSockHttp1.Post_data = Text4.Text
        WinSockHttp1.Head_cookie = CoS
        WinSockHttp1.Successflags = "flag xxxx" ’Set a flag to determine whether all required web pages have been downloaded. Sometimes we only need part of the webpage content
        WinSockHttp1.SockHttp "http://XXX.COM,", mPOST, "1011101"
    
    Private Sub WinSockHttp1_ReturnComplete( Arraydata() As Byte, Flags As String)
        
        strWeb = WinSockHttp1.Return_webstring ‘download complete string
                                                     ‘’Arraydata is bytearrays。
        'Debug.Print index
        'raw.debug_print strweb
    
    
    End Sub
    The code logic is not very clear. Modify it yourself, I suggest you use winhttp
    i am gettting error: Ambiguous name detected: BytesToBstr
    Attachment 178764

  17. #17
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    733

    Re: Vb6: Winsock grab full data on arrival

    Quote Originally Posted by geekmaro View Post
    i am gettting error: Ambiguous name detected: BytesToBstr
    Attachment 178764
    Code:
    Private Function BytesToBstr(ByRef arrBody() As Byte, ByVal CodeBase As String) As String
    
        Dim Objstream As Object
    
        Set Objstream = CreateObject("adodb.stream") '创建一个字符流....
        
        Objstream.Type = 1  '返回的数据类型 adTypeBinary  =1 adTypeText  =2
        Objstream.Mode = 3  '指定或返加模式 adModeReadWrite
        Objstream.Open  '指定打开模式,可不指定,可选参数如下:
        Objstream.Write (arrBody)
        
        Objstream.Position = 0
      
        Objstream.Type = 2
        Objstream.Charset = CodeBase
        
        Call Objstream.SaveToFile("c:\1.txt") '.ReadText(Objstream.Size)       '返回他的内容
        
        Objstream.LoadFromFile ("c:\1.txt")
        BytesToBstr = Objstream.ReadText
        Set Objstream = Nothing
    
        ' If Err.Number <> 0 Then BytesToBstr = ""
    
        On Error GoTo 0
    
    End Function

  18. #18

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    224

    Re: Vb6: Winsock grab full data on arrival

    Quote Originally Posted by xxdoc123 View Post
    Code:
    Private Function BytesToBstr(ByRef arrBody() As Byte, ByVal CodeBase As String) As String
    
        Dim Objstream As Object
    
        Set Objstream = CreateObject("adodb.stream") '创建一个字符流....
        
        Objstream.Type = 1  '返回的数据类型 adTypeBinary  =1 adTypeText  =2
        Objstream.Mode = 3  '指定或返加模式 adModeReadWrite
        Objstream.Open  '指定打开模式,可不指定,可选参数如下:
        Objstream.Write (arrBody)
        
        Objstream.Position = 0
      
        Objstream.Type = 2
        Objstream.Charset = CodeBase
        
        Call Objstream.SaveToFile("c:\1.txt") '.ReadText(Objstream.Size)       '返回他的内容
        
        Objstream.LoadFromFile ("c:\1.txt")
        BytesToBstr = Objstream.ReadText
        Set Objstream = Nothing
    
        ' If Err.Number <> 0 Then BytesToBstr = ""
    
        On Error GoTo 0
    
    End Function
    i keep getting same error: Ambiguous name detected: BytesToBstr

Tags for this Thread

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