【发布时间】:2023-10-15 14:13:01
【问题描述】:
我正在使用 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
我的问题是我需要等到我检查响应代码才能继续执行。
有什么方法可以在不使用计时器的情况下做到这一点?
谢谢, 亚历克斯
最终还是决定使用计时器。
【问题讨论】:
-
请注意...
response = response & strResponse对性能并不好,因为它会疯狂地重新分配字符串。如果期望性能和/或大响应,更好的方法是分配一个不需要在每个 DataArrival 上调整大小的大缓冲区,并将数据帧以正确的偏移量插入其中。 -
+1 好建议...我正在使用 strResponse 因为我还有另一个调用 strResponse = FormatLineEndings(strResponse)