Documente online.
Zona de administrare documente. Fisierele tale
Am uitat parola x Creaza cont nou
 HomeExploreaza
upload
Upload




Visual Basic 6.0 Tutorial

computers




Visual Basic 6.0 Tutorial - The most elementary single-thread Proxy-server 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).

(img/1.jpg)

Connect a new Winsock component to the project for work 717c216h with the network according to IP protocol

(img/2.jpg - img/4.jpg)

- Winsock component

Deploy two Winsock copies on the form. Winsock1 - 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.

(img/6.jpg)

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 - query for connection

(img/7.jpg)

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


     (img/8.jpg) - put port number 125 for the server part of Proxy

Change Proxy and port settings in Internet Explorer, if you use Internet Explorer

(img/io.jpg)

So that queries were sent to our Proxy

(img/lan.jpg)

LAN adjustment

(img/address.jpg)

Where (img/port.jpg) - 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

(img/demo.jpg)

Proxy-server operates - sends 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 and Winsock, create a working copy of the program.
    
    The entire VB project of this development stage is in the file
vbpt2.zip

© by Valery V Shmeleff (Oflameron)


Document Info


Accesari: 1485
Apreciat: hand-up

Comenteaza documentul:

Nu esti inregistrat
Trebuie sa fii utilizator inregistrat pentru a putea comenta


Creaza cont nou

A fost util?

Daca documentul a fost util si crezi ca merita
sa adaugi un link catre el la tine in site


in pagina web a site-ului tau.




eCoduri.com - coduri postale, contabile, CAEN sau bancare

Politica de confidentialitate | Termenii si conditii de utilizare




Copyright © Contact (SCRIGROUP Int. 2024 )