一个socket组件及其调用方法

作者:网络 来源:佚名 更新时间:2008-07-02 11:07:23 点击:

这个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

  • 本文来源于网页设计爱好者web开发社区http://www.html.org.cn收集整理,欢迎访问。