VB6 - 为什么我的winsock只收到一条消息? [英] VB6 - Why my winsock only recieves a piece of the message?

查看:73
本文介绍了VB6 - 为什么我的winsock只收到一条消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用winsock控件在VB6中编写程序。我正在使用winsock从php脚本请求数据,该脚本在base64中返回一个答案。



当我在网络浏览器中输入请求时,整个消息收到(大约700,000多个字符)。但是,当我通过VB6中的winsock控件执行请求时,我收到了响应的第一个数据包(大约7,000个字符)。我在某处读到HTTP 1.1发送不熟悉的块。



如果有人知道为什么会发生这种情况,请协助我解决它或指出我的方向会帮我理解如何解决这个问题吗?



提前谢谢

j3rg



编辑:

=====



但无论如何,经过更多研究,我发现以下链接可能有所帮助:< br $> b $ b

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



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



在此期间我会继续研究。



干杯

j3rg





编辑

====



好​​理查德谢谢你...抱歉,我没有注意到你的评论。是的我认为有更多的信息要收到,但我想知道如何接收其余信息,因为告诉服务器我需要其余的消息/数据。专家交流上面的链接给了我一些帮助。用户在论坛中发布了以下代码:



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


=====

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:

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:

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





区别在于我没有使用winsock控件数组,我检查ASCII字符255并且我将请求中的响应附加到文本中框。



当我执行我的代码时,我得到以下运行时错误40006 - 请求的事务或请求的协议或连接状态错误。我知道这个错误是由于连接在再次执行.PeekData之前关闭而发生的,这是由于代码中的DoEvents引起的。通过我的代码测试,DoEvents似乎是必要的。



专家交换链接解决了这个问题,我正在考虑这个问题。



关于投票,我只是不喜欢评价低的想法而不是说为什么那么愚蠢。但正如你所说,不要担心它所以你是对的我只是不给他们F ***我说他们因为它现在是LMAO。



感谢您的帮助



j3rg



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

推荐答案

好的我找到了解决办法。我只需要从PHP脚本返回的数据。我使用webbrowser控件导航到具有特定URL的地址,而不是使用winsock控件。阅读页面源代码使用:



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:

WebBrowser1.Document.Body.InnerText





如果有人使用这种方法,请注意您的程序将依赖于在您的系统上安装Internet Explorer。



希望这个帮助别人



欢呼



j3rg



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


这篇关于VB6 - 为什么我的winsock只收到一条消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆