Results 1 to 3 of 3

Thread: Proxy using winSockControl

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2000
    Location
    Portugal
    Posts
    2

    Question

    How do I specify a Proxy server using a WinSock Control in VB?
    CNT_MARX

  2. #2
    Lively Member
    Join Date
    Nov 1999
    Location
    Melbourne, Victoria, Australia
    Posts
    126

    Cool

    You can't specify a proxy server, the reason being
    winsock is raw sockets, no precoded functions, you must
    do all the hard work for yourself. You need to basically
    ask the proxy for the item you want and it will do it for you.
    See below for more details on how to do this...

    Depending on the setup of your proxy server you may or
    may not be able to go through the proxy itself. For exmaple
    if its a HTTP/FTP proxy and you want to get a webpage
    then this will work fine. However if its only a HTTP/FTP proxy
    and you want to do live chat via direct port access you can't use the
    proxy at all and therefore may not be able to create your desired program.

    If you have a SOCKS5 host on your lan/network speak to your admin on
    how to use and connect through the SOCKS5 host. If you have a normal
    HTTP/FTP proxy (most lan's/network's do) then use the below code...

    ** HTTP/FTP Proxy **
    ===============================================================
    Connect to the proxy on the specified port and ask for the page

    Dim TotalByes as Long
    'You will need to change these according to your proxy setup
    Const HTTPProxyAddress as String = "proxy.yourisp.com"
    Const HTTPProxyPort as Integer = 8080
    Dim HTTPURLAddress as String

    Private Sub CmdConnect_Click()

    'You will need to change this as well
    'You can use most common protocols just like in the browser

    'HTTP Get
    HTTPURLAddress = "http://www.vb-world.net/index.asp"

    'FTP GEt
    HTTPURLAddress = "ftp://ftp.microsoft.com/activex"

    sckSocket.Connect HTTPProxyAddress, HTTPProxyPort
    Me.caption = "Connecting to " & HTTPProxyAddress & "..."
    End Sub

    Private Sub sckSocket_Connect()
    sckSocket.SendData "GET " & HTTPURLAddress & " HTTP/1.0" & vbcrlf & vbcrlf
    Me.caption = "Connected to " & sckSocket.RemoteHostIP
    End Sub

    Private Sub sckSocket_DataArrival(bytes as long)
    sckSocket.GetData TempStr, vbstring
    TotalBytes = TotalBytes + bytes
    Me.caption = "Bytes read: " & TotalBytes
    TextHTML.Text = TextHTML.Text & TempStr
    End Sub

    Private Sub sckSocket_Close()
    Me.caption = "Download complete: " & TotalBytes & " bytes downloaded."
    End Sub







    Regards,

    Paul Rivoli
    ---------------------
    [email protected]
    http://members.dingoblue.net.au/~privoli

  3. #3
    Lively Member
    Join Date
    Nov 1999
    Location
    Melbourne, Victoria, Australia
    Posts
    126

    Cool

    You can't specify a proxy server, the reason being
    winsock is raw sockets, no precoded functions, you must
    do all the hard work for yourself. You need to basically
    ask the proxy for the item you want and it will do it for you.
    See below for more details on how to do this...

    Depending on the setup of your proxy server you may or
    may not be able to go through the proxy itself. For exmaple
    if its a HTTP/FTP proxy and you want to get a webpage
    then this will work fine. However if its only a HTTP/FTP proxy
    and you want to do live chat via direct port access you can't use the
    proxy at all and therefore may not be able to create your desired program.

    If you have a SOCKS5 host on your lan/network speak to your admin on
    how to use and connect through the SOCKS5 host. If you have a normal
    HTTP/FTP proxy (most lan's/network's do) then use the below code...

    ** HTTP/FTP Proxy **
    ===============================================================
    Connect to the proxy on the specified port and ask for the page

    [CODE]
    Dim TotalByes as Long
    'You will need to change these according to your proxy setup
    Const HTTPProxyAddress as String = "proxy.yourisp.com"
    Const HTTPProxyPort as Integer = 8080
    Dim HTTPURLAddress as String

    Private Sub CmdConnect_Click()

    'You will need to change this as well
    'You can use most common protocols just like in the browser

    'HTTP Get
    HTTPURLAddress = "http://www.vb-world.net/index.asp"

    'FTP GEt
    HTTPURLAddress = "ftp://ftp.microsoft.com/activex"

    sckSocket.Connect HTTPProxyAddress, HTTPProxyPort
    Me.caption = "Connecting to " & HTTPProxyAddress & "..."
    End Sub

    Private Sub sckSocket_Connect()
    sckSocket.SendData "GET " & HTTPURLAddress & " HTTP/1.0" & vbcrlf & vbcrlf
    Me.caption = "Connected to " & sckSocket.RemoteHostIP
    End Sub

    Private Sub sckSocket_DataArrival(bytes as long)
    sckSocket.GetData TempStr, vbstring
    TotalBytes = TotalBytes + bytes
    Me.caption = "Bytes read: " & TotalBytes
    TextHTML.Text = TextHTML.Text & TempStr
    End Sub

    Private Sub sckSocket_Close()
    Me.caption = "Download complete: " & TotalBytes & " bytes downloaded."
    End Sub
    [CODE]

    If you have any problems feel free to ask or email me
    Regards,

    Paul Rivoli
    ---------------------
    [email protected]
    http://members.dingoblue.net.au/~privoli

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width