开发者

VB6 winsock wait for response

开发者 https://www.devze.com 2023-04-04 21:26 出处:网络
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.

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_Da开发者_开发知识库taArrival(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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号