PDA

Click to See Complete Forum and Search --> : Proxy using winSockControl


Amaro Cantador
May 22nd, 2000, 10:44 PM
How do I specify a Proxy server using a WinSock Control in VB?

privoli
May 23rd, 2000, 02:07 PM
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

privoli
May 23rd, 2000, 02:08 PM
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