VB6winsock等待响应

发布于 2024-12-04 20:51:42 字数 631 浏览 1 评论 0原文

我正在使用 vb6 中的 Winsock 控件来检查 Web 服务的可用性。 我发出一个发布请求,获取响应并解析响应标头以检查响应代码。

响应以多个数据包形式到达。

' this event occurs when data is arriving via winsock
Private Sub wsTCP_DataArrival(ByVal bytesTotal As Long)
    Dim strResponse As String        
    wsTCP.GetData strResponse, vbString, bytesTotal
    strResponse = FormatLineEndings(strResponse)

    ' we append this to the response box becuase data arrives
    ' in multiple packets
    response = response & strResponse        
End Sub

我的问题是我需要等到检查响应代码才能继续执行。

有没有什么方法可以在不使用计时器的情况下做到这一点?

谢谢, 亚历克斯

最终决定使用计时器。

I am using the winsock control in vb6 to check the availability of a web service.
I do a post request, get the response and parse the response header to check the response code.

The response arrives in multiple packets.

' this event occurs when data is arriving via winsock
Private Sub wsTCP_DataArrival(ByVal bytesTotal As Long)
    Dim strResponse As String        
    wsTCP.GetData strResponse, vbString, bytesTotal
    strResponse = FormatLineEndings(strResponse)

    ' we append this to the response box becuase data arrives
    ' in multiple packets
    response = response & strResponse        
End Sub

My problem is that I need to wait until I check the response code to continue execution.

Is there any way to do this without using a timer?

Thanks,
Alex

decided to use the timer after all.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

メ斷腸人バ 2024-12-11 20:51:42

每次收到数据时,将其附加到缓冲区中,然后对其进行处理/解析。
它不必使用阻塞套接字,这意味着您可以在它到达时做出反应。
有关网络协议的示例,请参阅本文

Every time you receive data, append onto a buffer then process/parse that.
It gets around having to use the blocking sockets and means you can react when it arrives.
See this article on network protocols for an example.

迷路的信 2024-12-11 20:51:42

发送请求后,禁用 UI 中的控件(取消按钮或其他控件除外)。响应完成后,您可以启用 UI 并显示 DataArrival 中的结果,否则“继续”。

您确实不希望在 VB6 程序中阻塞套接字,它们会破坏整个 Windows 编程范例,因为您没有可用的工作线程。即使使用工作线程,您最终也会以相同的方式编码来“挂起”您的 UI 线程,因此不会有任何损失。

计时器可能是处理请求超时的最简单方法。

Disable the controls in your UI except for a Cancel button or something when you have sent the request. Once the response is complete you can enable the UI and display results from within DataArrival and otherwise "continue."

You really don't want blocking sockets in a VB6 program, they would break the whole Windows programming paradigm since you don't have worker threads available to you. Even with a worker thread you'd end up coding the same way to "suspend" your UI thread, so no loss there.

A Timer may be the easiest way to deal with request timeouts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文