• home
  • forum
  • my
  • kt
  • download
  • Simple proxy server in visual basic. Beginners tutorial.

    Author: 2007-09-06 09:54:06 From:

    Proxy on Visual Basic. Tutorial


    Free Visual Basic ebook download


        Ebook. Free VB eBook - The most elementary single-thread Proxy in Visual Basic. In creating this manual we set ourselves the task to develop a minimum program code playing the role of Proxy-server (transmitting information from one port to another). It is easy to add filtration functions to the program (it will be shown in the supplement), log records, information substitution records (link addresses, advertisement in HTML - for web site promotion).
        
         Free VB ebook Create standard Visual Basic project. Deploy element Label ¡°this computer¡¯s IP¡± on the form
        
        Form
        
        Connect a new

    Winsock component to the project for work with the network according to TCP/IP protocol
        
        Project Components  Winsock Control  Component
        
        Winsock -
    Winsock component
        
        Deploy two Winsock copies on the form. Winsock1 ¨C for the server part and Oflameron for the client part. The server part (Winsock1) receives queries from the Web-browser (for example, Internet Explorer) through the port, for example, 125 and transmits it to the client part. The client part Oflameron (Winsock2) through standard port 80 transmits queries to the real Web-server.

        Winsock
        
        

    Write the Proxy server part
        
        
    Private Sub Form_Load()

        Form1.Visible = True
        Do  ''Switch the server part to port listening ( Listen )
          If Winsock1.State <> sckConnected And Winsock1.State <> sckListening Then  ''If there is no connection yet and the port cannot be heard
          Beep
            Winsock1.Close  ''Close the connection
            Winsock1.LocalPort = 125  ''Port number for listening
            Winsock1.Listen  ''Begin listening port 125
          End If
          DoEvents
        Loop ''Repeat
        
    End Sub

        
        Connections processing
        
        
    Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
      ''If there is query for connection
        Winsock1.Close  ''Stop listening the port
        Winsock1.Accept requestID  ''Connect the client (browser) according to the number of the query
        
    End Sub

        
        Winsock1_ConnectionRequest ¨C query for
    connection
        
        Connection Request

        Announce the variable
        Dim ToServer As String  ''To send the query from the client part of Proxy to Web-server
        
        
        
    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)  ''Processing of incoming data (queries from Web-browser)
        Dim ServerData As String  ''Announce the variable for the received data ServerData
        Winsock1.GetData ServerData  ''Accept data into the variable
        ToServer = ServerData  ''Copy the query into the variable for sending to the Web-server
        Oflameron_SendToWebserver  ''Send the query to the Web-server
        
    End Sub

        
        Line ¡°ToServer = ServerData¡± - is not mandatory, it is worthwhile, if it is necessary to process data writing in the log, filter, search for data in queries, substitute information (for example, change URL in downloaded web-pages for one¡¯s own) etc.
        
        The entire VB project of this development stage is in the file
    vbpt1.zip
        
        
        
    Write the Client part of Proxy

        
        For work with real Web-server. Connection to Web-server, sending of queries and data receipt.
        
        Announce the variables
        
        Dim Webport  ''Port number
        Dim Data As String  ''To receive data from Web-server
        
        
    Private Sub Oflameron_SendToWebserver()
      ''Connect to Web-server
        Oflameron.Close  ''Close the connection
        Oflameron.RemoteHost = "10.62.182.54"  ''Web-server address or its IP address
        Oflameron.RemotePort = 80  ''Port number. Standard for HTTP
        Oflameron.Connect  ''Connect to Web-server
          Webport = Oflameron.RemotePort  ''Remember the port number (optional line)
        
    End Sub

        
        Procedure Oflameron_Connect performs actions as soon as the Web-server is connected
        
        
    Private Sub Oflameron_Connect()
      ''Sent query to Web-server
        If Oflameron.State <> sckConnected Then Exit Sub  ''Check. If there is no connection, abandon the procedure
        Oflameron.SendData ToServer  ''Send the query line to the Web-server
        
    End Sub

        
        The procedure of data receipt from the Web-server
        
        
    Private Sub Oflameron_DataArrival(ByVal bytesTotal As Long)
      ''The call will be initiated as soon as some data is received from the Web-server
          Text1.Text = Oflameron.State
        If Oflameron.State <> sckClosing Then
          Oflameron.GetData Data  ''It will contain data obtained from the Web-server
          Winsock1.SendData Data  ''Send the obtained data from Web server to Web-browser
        End If
        
    End Sub 
      
        HTTP- put port number 125 for the server part of Proxy
        
        Change Proxy and port settings in Internet Explorer, if you use IE
        
        Browser
        
        So that queries were sent to our Proxy
        
        LAN 
         
            IP
        
        Where LAN - the address of our Proxy (IP-address of your computer) and port 125, which will listen to the server part of your Proxy
        
        Upload the page from the Web-server to Internet Explorer
    website
        
        Website
        
        Proxy-server operates ¨Csends queries and received data.
        
        This is a working example of a most elementary Proxy-server in the minimal code configuration. It allows to understand important specifics of network programming, create a working copy of the program.
        
        The entire VB project of this development stage is in the file
    vbpt2.zip 
         
          

         

        
     Download Ebook 

    discuss this topic to forum

    relation tutorial

    No relevant information

    Category

      .NET (8)
      Buttons (3)
      Database Related (7)
      Date and Time (1)
      Development (3)
      Error Handling (2)
      File Manipulation (5)
      Introduction to Visual Basic (9)
      Miscellaneous (2)
      Multimedia (9)
      Networking (9)
      Security (1)
      VB Script (6)

    New

    Hot