Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I'm writing a program in VB6 using the winsock control. I'm using the winsock to request data from a php script that returns an answer in base64.

When I punch-in the request in my web browser the entire message is received (around 700,000+ characters). However when I do the request via my winsock control in VB6 I receive the firs packet of the response (around 7,000 characters). I read somewhere that HTTP 1.1 send in chunks not familiar with this.

If any knows why this is occurring please assist me with resolving it or point me in a direction that will help me understand how to resolve this issue?

Thanks in advance
j3rg

Edit:
=====

But anyway with more research I found the following links that might help:

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_21977116.html[^]

http://www.xtremevbtalk.com/showthread.php?t=248347[^]

In the meantime I'll keep researching.

Cheers
j3rg


Edit
====

OK Richard thank you ...Sorry I didn't notice your comment. Yes I figured there was more information to be received but I was wondering how to go about receiving the rest as in tell the server that I need the rest of the message/data. The link above from expert exchange gave me some help with this. A user form their forum posted the following code:

VB
Private Sub WskServer_DataArrival(Index As Integer, ByVal bytesTotal As Long)
 Dim sWork As String
 Dim sData As String
 Dim lRecv As Long

 Debug.Print "New data arrival detected @" & Time()
 Debug.Print "Begin receiving new data from (" & bytesTotal & " total bytes)"
 
 ' Retrieve the current block of data that is in the input
 ' buffer. We do this to EXACTLY make sure that we receive
 ' ALL the necessary data before clearing the buffer.
 Debug.Print "Analyzing the current data block for terminating characters"

 Do While True
   DoEvents
   WskServer(Index).PeekData sWork, vbString
   ' Look for the terminating character which should
   ' be always at the end of the data being received.
   If InStr(sWork, vbCrLf) Then
      Exit Do
   End If
 Loop
 
 lRecv = WskServer(Index).BytesReceived
 
 ' Now, retrieve the new data and then clear the buffer.
 Debug.Print "Retrieving the final data into our data variable (received " & lRecv & " of " & bytesTotal & " bytes)"
 WskServer(Index).GetData sData, vbString

End Sub


Mine is basically the same thing with slight modification:

VB
Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)
Dim sWork As String
Dim sData As String

Dim lRecv As Long

 Debug.Print "New data arrival detected @" & Time()
 Debug.Print "Begin receiving new data from (" & bytesTotal & " total bytes)"

 ' Retrieve the current block of data that is in the input
 ' buffer. We do this to EXACTLY make sure that we receive
 ' ALL the necessary data before clearing the buffer.
 Debug.Print "Analyzing the current data block for terminating characters"

 Do While True
   DoEvents

   Winsock.PeekData sWork, vbString
   ' Look for the terminating character which should
   ' be always at the end of the data being received.

   If InStr(sWork, Chr(255)) Then
      Exit Do
   End If

 Loop

 lRecv = Winsock.BytesReceived

 ' Now, retrieve the new data and then clear the buffer.
 Debug.Print "Retrieving the final data into our data variable (received " & lRecv & " of " & bytesTotal & " bytes)"
 Winsock.GetData sData, vbString

 Text1.Text = sData
    
End Sub


The difference is just that I'm not using a winsock control array, I check for ASCII character 255 and I'm appending the responses from the request into a text box.

When I execute my code I get the following run-time error "40006 - Wrong protocol or connection state for the requested transaction or request". I know this error is occurring due to the connection being close before another execution of the .PeekData again and this is caused due to the DoEvents in the code. The DoEvents seems necessary through my testing of the code.

The expert exchange link address this issue and I am currently looking at that.

And about the vote I just didn't like the idea of rating it low and not saying why that's dumb. But as you say don't worry about it so you're right I just don't give a F*** about them and I say them because its 2 now LMAO.

Thank you for your assistance

j3rg
Posted
Updated 10-Jun-14 7:47am
v5
Comments
Richard MacCutchan 7-Jun-14 4:57am    
Chances are there is more data still to be received but your program is not reading it.
Richard MacCutchan 10-Jun-14 10:50am    
Did you notice my comment? If you want all the data then you need to keep reading until the socket signals no more data available. Unfortunately, since you have not shown the actual code that reads the socket we cannot make any guesses as to whether it is doing it correctly or not.

And don't worry about downvotes, they do you no harm.

1 solution

OK I found a work around. I simply needed the data returned from the PHP script. Instead of using the winsock control I used the webbrowser control navigate to the address with the specific URL. Read the page source using:

VB
WebBrowser1.Document.Body.InnerText


If anyone uses this method be aware that your program will be dependent on having Internet Explorer installed on your system.

Hope this helps someone else

cheers

j3rg
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900