一个socket组件及其调用方法

2008-02-23 05:31:15来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

这个socket组件是由开发jmail的那家公司作的。
很老的一个版本了。不过挺好的。我一直在用。
比较稳定。以前发现xmlhttp在win2003 server上不太好。流量大了iis容易当掉。用这个组件倒还算稳定。

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

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:XLS与MDB文件格式互换全攻略

下一篇:ASP模仿asp.net的DataGrid