Web Proxy (Creating One)

Posted on 2000-04-12
Last Modified: 2013-11-25
Can one create a web proxy using Visual Basic? If yes, I'll up the points for a "how" section to that answer!
Question by:ayrezyle
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
LVL 12

Expert Comment

ID: 2708543
While you might be able to create a web proxy in VB generally you wouldn't want to as you should put in a Linux box up instead of a Windoze OS. This would therefore eliminate *any* Micro$oft GUI product from being used as a proxy server development base.


Expert Comment

ID: 2709611
Rather then bash Microsoft, I will tell you that it can be done.  Tell me more about what you wish to do and I might already have some code for you.
LVL 12

Expert Comment

ID: 2709773
Not bashing M$. Simply saying that GUI is weak point in this type of app. You want *TIGHT*, *FAST* and *Rugged*. Windows/VB provides none of these and is inappropriate choice for this application. You can write it in VB on Windows, but system will *NOT* work reliably and will be easily breached. Is NOT how you want proxy server/firewall to behave. Why do you need a GUI on a box that will be locked in a closet? You could add a bath tub to a drag racing car but it wouldn't help it go any faster or run any better - so what is point?

Windows is inappropriate for tight realtime applications. You simply cannot write robust, highly I/O intensive code with all of overhead that the GUI implies. I've written quite a bit of firmware and embedded processor code and GUI overhead is not appropriate even if you *can* get it running.

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users


Expert Comment

ID: 2709838
How do you know how I/O intensive his application is going to be?  No time to argue though and there is no point to it until we know what he wants to do with it.

Take care,
LVL 14

Accepted Solution

mcrider earned 100 total points
ID: 2710436
When building a proxy server in VB basically, they work like this:

You have a winsock control that is running as a server.  It is listening on a specific port waiting for a connection.

Once this socket receives a connection (ACCEPT SOCKET), the code would open another connection using another socket to the "real destination" (PROXY SOCKET).

Usually, before the PROXY SOCKET is opened, information about where the "real destination" is located is passed from the client.  For example, in a HTTP proxy, URL sent contains the system name that the proxy server should connect to.

Depending on the protocol you are building the procy for, the code would "pump" everything it receives from the ACCEPT SOCKET to the PROXY SOCKET... and everything it recives from the PROXY SOCKET to the ACCEPT SOCKET.

FTP, for example is much more difficult to provide proxy services for that HTTP because HTTP only uses 1 socket for transmission, whereas, FTP uses 2 sockets...

I am assuming that you already know how to program using the winsock control... If not, take a look at the Help page and "Books online..." for the control.

Here's an example of a proxy for HTTP using the winsock controls that I put together... Remember, this is a BASIC EXAMPLE that I threw together.

1) Create a new project.

2) add 2 winsock controls to the form and change the INDEX property of both controls to 0

3) Add the following code to the DECLARATIONS SECTION of the form:

        Dim RollingSocket As Integer
    Private Sub Form_Load()
        Winsock1(0).LocalPort = 80
    End Sub
    Private Sub Winsock1_Close(Index As Integer)
        On Error Resume Next
        Unload Winsock1(Index)
        Unload Winsock2(Index)
    End Sub
    Private Sub Winsock1_ConnectionRequest(Index As Integer, ByVal requestID As Long)
        Dim iVal As Long
        RollingSocket = RollingSocket + 1
        If RollingSocket = 200 Then RollingSocket = 1
        Load Winsock1(RollingSocket)
        Winsock1(RollingSocket).Accept requestID
    End Sub
    Private Sub Winsock1_DataArrival(Index As Integer, ByVal bytesTotal As Long)
        Dim iVal As Long
        Dim jVal As Long
        Dim lBuf As String
        Dim lCmd As String
        Dim lFunct As String
        Dim lUrl As String
        Dim lVer As String
        Dim lHost As String
        Dim ProxyServer As Integer
        On Error Resume Next
        With Winsock1(Index)
            .GetData lBuf
            .Tag = .Tag + lBuf
            If Right$(.Tag, 4) = vbCrLf + vbCrLf Then
                iVal = InStr(1, .Tag, vbCrLf)
                lCmd = Left$(.Tag, iVal - 1)
                .Tag = Mid$(.Tag, iVal + 2)
                iVal = InStr(1, lCmd, " ")
                jVal = InStr(iVal + 1, lCmd, " ")
                lFunct = Left$(lCmd, iVal - 1)
                iVal = iVal + 1
                lUrl = Mid$(lCmd, iVal, jVal - iVal)
                lVer = Mid$(lCmd, jVal + 1)
                iVal = InStr(1, lUrl, "://") + 3
                jVal = InStr(iVal, lUrl, "/")
                lHost = Mid$(lUrl, iVal, jVal - iVal)
                lUrl = Mid$(lUrl, iVal + Len(lHost))
                .Tag = lFunct + " " + lUrl + " " + lVer + vbCrLf + .Tag
                'CALL THE PROXY SOCKET
                ProxyServer = Index
                Load Winsock2(ProxyServer)
                Winsock2(ProxyServer).RemoteHost = lHost
                Winsock2(ProxyServer).RemotePort = 80
            End If
        End With
    End Sub
    Private Sub Winsock2_Close(Index As Integer)
        On Error Resume Next
        Unload Winsock1(Index)
        Unload Winsock2(Index)
    End Sub
    Private Sub Winsock2_Connect(Index As Integer)
        On Error Resume Next
        Winsock2(Index).SendData Winsock1(Index).Tag
    End Sub
    Private Sub Winsock2_DataArrival(Index As Integer, ByVal bytesTotal As Long)
        Dim lByte() As Byte
        Winsock2(Index).GetData lByte, vbByte
        Winsock1(Index).SendData lByte
    End Sub

4) Run the program.

5) From another system, configure the browser proxy to be the system you're running this program on. (use port 80)

By the way, I think this is worth much more than 10 points... Don't you??  EE guidelines for asking questions are:

     50 points for an easy question
     100 points for a moderate question
     200 points for a hard question



Author Comment

ID: 2726462
Adjusted points from 10 to 100

Author Comment

ID: 2726463
Let me settle this one before someone draws blood :-) My case is a special one. Firstly, I am a C++ fan and also like nice & tight code. However, I don't have the time to learn VC++ which is my first choice of platform for this app. I'm already strong on VB using COM, which is why I want to do this in VB. Later on, I can migrate the component doing the actual work to a nice & tight VC++ COM component using ATL and all those niceties.

Why VB on NT? I want to create management features for a proxy; the proxy itself doesn't concern me much.

Regarding the performance issue: I'm running this proxy on a dual Pentium 2 350Mhz (200+MB RAM) servicing 40 people sharing a single 64kbps line. It won't break a sweat.

mcrider, you'll notice I've already upped the points :) You're #1 atm, I'll check out the code tonight.

Author Comment

ID: 2727977
mcrider, I'm impressed!! Cut&Paste and it works! now I need to sit down and check out what you did!

I take it you've previously worked with TCP/IP headers?

One more thing... I assume that if I match the port numbers to the requested ports, I'll be able to use SSL and FTP too? (FTP will be a different header though; will SSL?)

How much memory does that control array take (per element)?

Where on the Net do I get a description of those headers?
LVL 14

Expert Comment

ID: 2731949
>>mcrider, I'm impressed!! Cut&Paste and it works!

Glad I could help you... It's not very often that I post code that dies when you cut and paste it. ;-)

Yes, I have worked with TCP headers.  In fact, Secure Firewall Technology (not in VB) is where I've made my millions.  As for SSL, you should be able to change the ports, however, FTP is a multi-socket protocol and it is *MUCH* more difficult.  It requires 2 separate sockets... Ports 20 and 21.

I suggest that if you are going to be going deep in this subject, you look at the RFCs for each protocol.  You can find them by going to and doing a search for "+RFC +FTP" (don't use the quotes)


Expert Comment

ID: 7917395

i know it's been nearly 3 years since this thread has started however i've just found it.

i've created the program and it runs semi well. I get inconsistent results.

if i point my broswer to the proxy and point my browser to a site such as i get inconsitent results. The first time only half the page will come through, the second time even less then the next time the page will come in fully and so on.

Any thoughts?

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In a recent question ( here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question