一個socket組件及其調(diào)用方法
發(fā)表時間:2024-02-03 來源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]這個socket組件是由開發(fā)jmail的那家公司作的。很老的一個版本了。不過挺好的。我一直在用。比較穩(wěn)定。以前發(fā)現(xiàn)xmlhttp在win2003 server上不太好。流量大了iis容易當(dāng)?shù)。用這個組件倒還算穩(wěn)定。 paraHost ="www.knowsky.com" ...
這個socket組件是由開發(fā)jmail的那家公司作的。
很老的一個版本了。不過挺好的。我一直在用。
比較穩(wěn)定。以前發(fā)現(xiàn)xmlhttp在win2003 server上不太好。流量大了iis容易當(dāng)?shù)簟S眠@個組件倒還算穩(wěn)定。
paraHost ="www.knowsky.com" ' host
paraPort = 80 ' port
paraFileUrl ="/test/test.htm"
Set Socket = CreateObject("Socket.TCP")
Socket.Host = paraHost & ":" & paraPort
Socket.Timeout = paraTimeout
If Err.Number <> 0 Then Err.Clear
Socket.open
' timeout error = 8000ffff
Socket.SendLine "GET " & paraFileUrl & " HTTP/1.0"
Socket.SendLine "HOST: " & paraHost
Socket.SendLine ""
Socket.SendLine ""
'Sleep 200
Socket.WaitForDisconnect
If Err.Number <> 0 Then
response.write Err.Number & " -- " & Err.Description
Err.Clear
Else
response.write HTTPResponse(Socket.Buffer, 1) ' output text from socket
End If
Socket.Close
Set Socket = Nothing
Private Function HTTPResponse(ByVal toHTTPResponse, ByVal whichHTTPResponse)
On Error Resume Next
Dim HTTPResponseDelimiter
HTTPResponseDelimiter = Chr(13) & Chr(10) & Chr(13) & Chr(10)
If (InStr(1, toHTTPResponse, HTTPResponseDelimiter, vbBinaryCompare) <> 0) Then
Select Case whichHTTPResponse
Case 0 'Header
HTTPResponse = Mid(toHTTPResponse, 1, (InStr(1, toHTTPResponse, HTTPResponseDelimiter, vbBinaryCompare) - 1))
Case 1 'Body
HTTPResponse = Mid(toHTTPResponse, (InStr(1, toHTTPResponse, HTTPResponseDelimiter, vbBinaryCompare) + Len(HTTPResponseDelimiter)), (Len(toHTTPResponse) - (InStr(1, toHTTPResponse, HTTPResponseDelimiter, vbBinaryCompare) - 1)))
End Select
End If
End Function