Results 1 to 24 of 24

Thread: Vb6: Winsock data arrival truncated problem

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    224

    Vb6: Winsock data arrival truncated problem

    I have this code, but it only grab truncated data, the data is a little bit large, it is a page source code

    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)

    Dim strResponse As String
    Winsock1.GetData strResponse, vbString
    RichTextBox1.Text = RichTextBox1.Text & strResponse

    please help to fix this problem

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    224

    Re: Vb6: Winsock data arrival truncated problem

    there is something strange i cant understand
    when i click manually on command1 to get page source code on data arrival, i get all info to textbox without problem
    but when i do it automatically, like get data on keyword found then i get truncated data into textbox

    If InStr(strResponse, "login") Then
    call command1_click
    end if

    i have this code on data arrival and it should automatically make a get request but it can only get truncated data
    help please

  3. #3
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: Vb6: Winsock data arrival truncated problem

    Quote Originally Posted by geekmaro View Post
    help please
    No one can help without showing the *full* code that is not behaving ok according to you. FYI, Winsock control is working fine here and probably there is no problem at your site too.

    So most probably the error is either within your code (cannot tell without seeing it) or within your understanding of how http over TCP/IP actually works (very probable considering the OP and the follow up post).

    cheers,
    </wqw>

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    224

    Re: Vb6: Winsock data arrival truncated problem

    what i understood is that in post request i have to wait until data received first
    before i make a new request
    anyone can help me with code please ?

  5. #5
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,414

    Re: Vb6: Winsock data arrival truncated problem

    Is it a multiline-textbox (incl. expanded on the form to be bigger and show more lines than the "standard" one line?
    Maybe there is a vbCrLF/chr(0) hidden in your data arriving......
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    224

    Re: Vb6: Winsock data arrival truncated problem

    Quote Originally Posted by Zvoni View Post
    Is it a multiline-textbox (incl. expanded on the form to be bigger and show more lines than the "standard" one line?
    Maybe there is a vbCrLF/chr(0) hidden in your data arriving......
    textbox is richtextbox multiline and there is no vbCrLF/chr(0)
    i am using this right now, but still not working properly

    If InStr(strResponse, "login") & Winsock1.BytesReceived Then
    call command1_click
    end if

    it basically wait for winsock to finish to make another request but i am not sure why it not work well

  7. #7
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: Vb6: Winsock data arrival truncated problem

    Quote Originally Posted by geekmaro View Post
    it basically wait for winsock to finish to make another request but i am not sure why it not work well
    Cannot tell without taking a look at the code. In ConnectionRequest you have to load a new instance of the Winsock control and call its Accept method with current requestID. It's this new instance which will receive data on the new client connection in the DataArrival event, not the original Winsock control that is Listen-ing for incomming connections.

    cheers,
    </wqw>

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    224

    Re: Vb6: Winsock data arrival truncated problem

    Quote Originally Posted by wqweto View Post
    Cannot tell without taking a look at the code. In ConnectionRequest you have to load a new instance of the Winsock control and call its Accept method with current requestID. It's this new instance which will receive data on the new client connection in the DataArrival event, not the original Winsock control that is Listen-ing for incomming connections.

    cheers,
    </wqw>
    oh i didnt know about Accept method with current requestID
    but i dont want to close winsock on new request, i want to keep winsock connected

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    224

    Re: Vb6: Winsock data arrival truncated problem

    Private Sub Winsock1_ConnectionRequest(ByVal RequestID As Long)
    Winsock1.Accept RequestID
    End Sub

    same problem

  10. #10
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: Vb6: Winsock data arrival truncated problem

    Well, find a working sample code on using Winsock control to build a client/server application -- chat or anything else.

    Best would be to study this and then base your efforts on a working code -- much easier.

    cheers,
    </wqw>

  11. #11
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    673

    Re: Vb6: Winsock data arrival truncated problem

    you are right.

  12. #12
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,871

    Re: Vb6: Winsock data arrival truncated problem

    Code:
    If InStr(strResponse, "login") & Winsock1.BytesReceived Then
    call command1_click
    end if
    Is this actual code??
    Because this "If InStr(strResponse, "login") & Winsock1.BytesReceived Then" will never work
    Use And instead of &

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    224

    Re: Vb6: Winsock data arrival truncated problem

    so after spending the whole day working on this, i found the problem but dont know how to fix

    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)

    Dim strResponse As String
    Winsock1.GetData strResponse, vbString
    RichTextBox1.Text = RichTextBox1.Text & strResponse
    Msgbox "Done" = right here this msgbox would show twice and this is the problem, i saw strResponse pasted into RichTextBox1.text twice on 2 parts
    i need whole to strResponse once in full, not on 2 parts
    please help

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    224

    Re: Vb6: Winsock data arrival truncated problem

    i only need to get page html source code with winsock
    anyone can give me code to do it please
    thanx

  15. #15
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    460

    Re: Vb6: Winsock data arrival truncated problem

    Quote Originally Posted by geekmaro View Post
    i only need to get page html source code with winsock
    anyone can give me code to do it please
    thanx
    does it have to be winsock? will this work for you?

    Code:
    Public Function WebRequest(url As String) As String
        Dim http As Object
        Set http = CreateObject("MSXML2.ServerXMLHTTP")
    
        http.Open "GET", url, False
        http.Send
    
        WebRequest = http.responseText
        Set http = Nothing
    End Function

  16. #16

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    224

    Re: Vb6: Winsock data arrival truncated problem

    Only winsock please
    The server send data in 2 batchs.
    how can i get both 2 batchs into textbox at once ?

  17. #17
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: Vb6: Winsock data arrival truncated problem

    The server can send 3 batches. The server can send multiple batches. There is no guarantee how many and in what intervals. You already do RichTextBox1.Text = RichTextBox1.Text & strResponse so there is no problem with chunking.

    The problem is to figure out when you have the whole response. You have to parse "Content-Length" header and sum the size of all batches received. This is what XMLHTTP and WinHttpRequest are going to save you from implementing incorrectly.

    cheers,
    </wqw>

  18. #18

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    224

    Re: Vb6: Winsock data arrival truncated problem

    Quote Originally Posted by wqweto View Post
    The server can send 3 batches. The server can send multiple batches. There is no guarantee how many and in what intervals. You already do RichTextBox1.Text = RichTextBox1.Text & strResponse so there is no problem with chunking.

    The problem is to figure out when you have the whole response. You have to parse "Content-Length" header and sum the size of all batches received. This is what XMLHTTP and WinHttpRequest are going to save you from implementing incorrectly.

    cheers,
    </wqw>
    i already thought about "Content-Length" but it is not fixed, because page has data that changes each time
    please help, i have spent the whole day looking everywhere and tried everything..

  19. #19
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    673

    Re: Vb6: Winsock data arrival truncated problem

    wait. I will upload a demo. but I need a URL to test

    It is difficult to connect to https using winsock.

    so i used serverhttp or winhttp . you can test
    Attached Files Attached Files
    Last edited by xxdoc123; Sep 30th, 2020 at 08:41 PM.

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    224

    Re: Vb6: Winsock data arrival truncated problem

    Quote Originally Posted by xxdoc123 View Post
    wait. I will upload a demo. but I need a URL to test

    It is difficult to connect to https using winsock.

    so i used serverhttp or winhttp . you can test
    interesting control, but how can i make post request to login page? something like this:
    Inet1.Execute "http://admin.5socks.net", "POST", "login=user&password=pass", "Content-Type: application/x-www-form-urlencoded"

  21. #21
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    673

    Re: Vb6: Winsock data arrival truncated problem

    NetSvervhttp1. SendData "http://admin.5socks.net",EN_POST, "login=user&password=pass", "Content-Type: application/x-www-form-urlencoded", , , "test"

    SendData(URE As String, [SenaWe thod As ENn SENDMETHOD], [PostData], [Heads As String], [RefUrI As String], [Cookire As String], [FIags As
    5tring=“标记“]) As Boolean
    Last edited by xxdoc123; Oct 1st, 2020 at 02:09 AM.

  22. #22

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    224

    Re: Vb6: Winsock data arrival truncated problem

    Quote Originally Posted by xxdoc123 View Post
    NetSvervhttp1. SendData "http://admin.5socks.net",EN_POST, "login=user&password=pass", "Content-Type: application/x-www-form-urlencoded", , , "test"

    SendData(URE As String, [SenaWe thod As ENn SENDMETHOD], [PostData], [Heads As String], [RefUrI As String], [Cookire As String], [FIags As
    5tring=“标记“]) As Boolean
    amazing control it worked, i just need one last thing that is to get cookies and make a post request using cookies
    thats all i need please help

  23. #23

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    224

    Re: Vb6: Winsock data arrival truncated problem

    i tried this but it didnt work
    Text2.Text = NetSvervhttp1.getCookies

  24. #24

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    224

    Re: Vb6: Winsock data arrival truncated problem

    the control has some characters that my pc cant read, could you please upload only the control again ?
    look at this for example:
    here photo:
    https://prnt.sc/ur400f


    Private Sub Timer1_Timer()

    Dim tempCookie As String, tempSetCookie As String

    If priStatus = EN_STOP Then Exit Sub 'Èç¹ûµ±Ç°ÊÇֹͣ״̬ÔòÍ˳ö
    If priStatus <> EN_STOP Then
    CurrentImage = (CurrentImage + 1) Mod Image1.Count
    Image1(CurrentImage).ZOrder vbBringToFront

    End If

    On Error GoTo SilenceErr

    Select Case NET.readyState 'ÅжÏ״̬

    Case 4 '·¢ËÍÍê³É

    If NET.Status = 200 Then 'NET.Status = 200 Or NET.Status = 206 Or NET.Status = 400 Or NET.Status = 302 Then 'httpÏìÓ¦´úÂëΪ200¡¡ÇëÇóok
    priStatus = EN_STOP
    priHeaders = NET.getAllResponseHeaders
    priCookies = ´¦ÀíCookie(priHeaders)
    m_BytReturn_Responsebodys = NET.responseBody
    Abort
    RaiseEvent SendComplete(m_StrFlags) 'Çý¶¯Ê¼þ

    Exit Sub
    Else
    priErrInfo = "·þÎñÆ÷ÏìÓ¦´úÂë:" & NET.Status

    RaiseEvent SendError(priErrInfo, m_StrFlags)

    End If

    Case 3 'Or 2 ¿ÉÒÔ»ñµÃÍ·Îļþ

    End Select

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