A socket component and its calling method

Source: Internet
Author: User
Tags chr set socket socket

This socket component is made by the company that developed JMail.
A very old version of it. But it's pretty good. I've been using it all the time.
More stable. It was previously found that XMLHTTP was not very good on Win2003 server. The traffic is big and IIS is easy to drop. It's stable with this component.

Parahost = "www.knowsky.com"' Host
Paraport = ' 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
& nbsp;   socket.close
    Set Socket = Nothing

Private Function HttpResponse (ByVal tohttpresponse, ByVal whichhttpresponse)
On Error Resume Next
Dim Httpresponsedelimiter

Httpresponsedelimiter = Chr & Chr (a) & Chr (a) & 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



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.