Beruflich Dokumente
Kultur Dokumente
Tutorial
Ebook. Free Tutorial - 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).
Create standard Visual Basic project. Deploy element Label this computers IP on the form
Connect a new Winsock component to the project for work with the network according to IP protocol
- 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.
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
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 ones own) etc.
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
LAN adjustment
Where - the address of our Proxy (IP-address of your computer) and port 125, which will listen to the server part
of your Proxy
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.
Free Tutorials: