我正在使用vb6中的winsock控件来检查Web服务的可用性。 我做了一个post请求,获取响应并解析响应头以检查响应代码。VB6 winsock等待响应
响应到达多个数据包。
' 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
我的问题是,我需要等到检查响应代码才能继续执行。
有没有办法做到这一点,而不使用计时器?
谢谢, 亚历克斯
决定使用定时器毕竟。
只需注意......'response = response&strResponse'对于性能来说并不是很好,因为它会像疯狂一样重新分配字符串。如果期望性能和/或较大的响应,则更好的方法是分配一个不需要在每个DataArrival上调整大小的大缓冲区,并将数据帧插入到正确的偏移量处。 – tcarvin
+1好adivice ...我使用strResponse,因为我有另一个调用strResponse = FormatLineEndings(strResponse) – thedev