i have added comments to where i have bugs
Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class frmMain
Inherits System.Windows.Forms.Form
Private Const DEBUG_MODE As Boolean = False
'collection to hold data buffer for each connections
'serverconnection keep the buffer for the sckserver socket (which sent the data to browser client)
'clientconnection keep the buffer for the sckclient socket (which sent the data to the host server or the proxy server)
Dim ServerConnection As Collection
Dim ClientConnection As Collection
Private Sub cmdClearLog_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdClearLog.Click
lstLog.Items.Clear()
txtRequest.Text = ""
txtResponse.Text = ""
End Sub
Private Sub cmdConfiguration_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdConfiguration.Click
LoadConfigurationScreen(Me, netProxy)
End Sub
Private Sub cmdSwitch_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSwitch.Click
If cmdSwitch.Text = "Start" Then
StartProxy(ListeningPort)
cmdSwitch.Text = "Stop"
Else
StopProxy()
cmdSwitch.Text = "Start"
End If
End Sub
Private Sub StartProxy(ByRef LocalPort As Integer)
'starting the server by binding the local port property to the listening port we use for proxy
'and issue the listen method to start listening
SendToLog("Initializing Proxy server")
InitializeSocket(sckServer(0))
sckServer(0).LocalPort = LocalPort
sckServer(0).Listen()
SendToLog("Listening on port " & LocalPort)
End Sub
Private Sub StopProxy()
Dim Socket As AxMSWinsockLib.AxWinsock
'looping each connections and close 'em
SendToLog("Disconnecting all connection")
For Each Socket In sckServer
tmrServer(Socket.Index).Enabled = False 'the erro am having is index not a member of AxMSWinsockLib.AxWinsock
tmrClient(Socket.Index).Enabled = False 'the erro am having is index not a member of AxMSWinsockLib.AxWinsock
System.Windows.Forms.Application.DoEvents()
CloseSocket(Socket.Index) 'the erro am having is index not a member of AxMSWinsockLib.AxWinsock
Next Socket
SendToLog("Proxy server stopped")
End Sub
Private Sub InitializeSocket(ByRef Socket As AxMSWinsockLib.AxWinsock)
On Error Resume Next
'initialize socket before use
SendToLog("Initialize Socket " & Socket.LocalPort)
Socket.Close()
Socket.LocalPort = 0
End Sub
Private Sub SendToLog(ByRef Message As String)
lstLog.Items.Add("[" & Now & "] " & Message)
If lstLog.Items.Count > 10000 Then lstLog.Items.Clear()
End Sub
Private Sub flxStatistic_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles flxStatistic.ClickEvent
Dim i As Integer
With flxStatistic
For i = 1 To ConnectionRequest.Count()
System.Windows.Forms.Application.DoEvents()
If i = .Rows Then
.Rows = .Rows + 1
.set_TextMatrix(i, 0, i)
'UPGRADE_WARNING: Couldn't resolve default property of object ConnectionRequest().IPAddress. Click for more: 'ms-help:
.set_TextMatrix(i, 1, ConnectionRequest.Item(i).IPAddress)
'UPGRADE_WARNING: Couldn't resolve default property of object ConnectionRequest().HostName. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
.set_TextMatrix(i, 2, ConnectionRequest.Item(i).HostName)
End If
'UPGRADE_WARNING: Couldn't resolve default property of object ConnectionRequest().Stat_Connect_Count. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
.set_TextMatrix(i, 3, ConnectionRequest.Item(i).Stat_Connect_Count)
Next i
End With
End Sub
Private Sub frmMain_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
LocalIP = sckServer(0).LocalIP
LoadUser(UserList, "UserList.txt")
InitializeGrid()
netProxy = New CProxy
'UPGRADE_WARNING: Dir has a new behavior. Click for more: 'ms-help:
If Len(Dir(My.Application.Info.DirectoryPath & "\" & ConfigFileName)) = 0 Then LocalComputerName = sckServer(0).LocalHostName
LoadProxyConfiguration()
ServerConnection = New Collection
ClientConnection = New Collection
End Sub
'UPGRADE_WARNING: Event frmMain.Resize may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
Private Sub frmMain_Resize(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Resize
tabProxy.Width = Me.ClientRectangle.Width
If VB6.PixelsToTwipsY(Me.ClientRectangle.Height) > (VB6.PixelsToTwipsY(cmdSwitch.Height) - 30) Then
tabProxy.Height = VB6.TwipsToPixelsY(VB6.PixelsToTwipsY(Me.ClientRectangle.Height) - (VB6.PixelsToTwipsY(cmdSwitch.Height) - 30))
End If
If VB6.PixelsToTwipsX(tabProxy.Width) > 200 Then
fraLog.Width = VB6.TwipsToPixelsX(VB6.PixelsToTwipsX(tabProxy.Width) - 200)
fraStat.Width = VB6.TwipsToPixelsX(VB6.PixelsToTwipsX(tabProxy.Width) - 200)
End If
If VB6.PixelsToTwipsY(tabProxy.Height) > 500 Then
fraLog.Height = VB6.TwipsToPixelsY(VB6.PixelsToTwipsY(tabProxy.Height) - 500)
fraStat.Height = VB6.TwipsToPixelsY(VB6.PixelsToTwipsY(tabProxy.Height) - 500)
End If
If VB6.PixelsToTwipsX(fraLog.Width) > 200 Then
lstLog.Width = VB6.TwipsToPixelsX(VB6.PixelsToTwipsX(fraLog.Width) - 200)
flxStatistic.Width = VB6.TwipsToPixelsX(VB6.PixelsToTwipsX(fraStat.Width) - 200)
End If
If VB6.PixelsToTwipsY(fraLog.Height) > 240 Then
lstLog.Height = VB6.TwipsToPixelsY(VB6.PixelsToTwipsY(fraLog.Height) - 240)
End If
If VB6.PixelsToTwipsY(fraStat.Height) > 320 Then
flxStatistic.Height = VB6.TwipsToPixelsY(VB6.PixelsToTwipsY(fraStat.Height) - 320)
End If
fraRequest.Width = fraLog.Width
fraRequest.Height = VB6.TwipsToPixelsY(VB6.PixelsToTwipsY(fraLog.Height) \ 2)
If VB6.PixelsToTwipsY(fraRequest.Height) > 400 Then
txtRequest.Height = VB6.TwipsToPixelsY(VB6.PixelsToTwipsY(fraRequest.Height) - 400)
End If
If VB6.PixelsToTwipsX(fraRequest.Width) > 300 Then
txtRequest.Width = VB6.TwipsToPixelsX(VB6.PixelsToTwipsX(fraRequest.Width) - 300)
End If
fraResponse.Top = VB6.TwipsToPixelsY(VB6.PixelsToTwipsY(fraRequest.Top) + VB6.PixelsToTwipsY(fraRequest.Height))
fraResponse.Width = fraLog.Width
fraResponse.Height = VB6.TwipsToPixelsY(VB6.PixelsToTwipsY(fraLog.Height) \ 2)
If VB6.PixelsToTwipsY(fraResponse.Height) > 400 Then
txtResponse.Height = VB6.TwipsToPixelsY(VB6.PixelsToTwipsY(fraResponse.Height) - 400)
End If
If VB6.PixelsToTwipsX(fraResponse.Width) > 300 Then
txtResponse.Width = VB6.TwipsToPixelsX(VB6.PixelsToTwipsX(fraResponse.Width) - 300)
End If
With flxStatistic
.set_ColWidth(0, System.Math.Abs(500 / 4500 * (VB6.PixelsToTwipsX(.Width) - 100)))
.set_ColWidth(1, System.Math.Abs(1000 / 4500 * (VB6.PixelsToTwipsX(.Width) - 100)))
.set_ColWidth(2, System.Math.Abs(2000 / 4500 * (VB6.PixelsToTwipsX(.Width) - 100)))
.set_ColWidth(3, System.Math.Abs(1000 / 4500 * (VB6.PixelsToTwipsX(.Width) - 100)))
End With
End Sub
Private Sub frmMain_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
Dim Socket As AxMSWinsockLib.AxWinsock
'unload socket control array
For Each Socket In sckClient
CloseSocket(Socket.Index) 'the erro am having is index not a member of AxMSWinsockLib.AxWinsock
If Socket.Index <> 0 Then 'the erro am having is index not a member of AxMSWinsockLib.AxWinsock
Socket.Dispose()
End If
Next Socket
For Each Socket In sckServer
CloseSocket(Socket.Index) 'the erro am having is index not a member of AxMSWinsockLib.AxWinsock
If Socket.Index <> 0 Then 'the erro am having is index not a member of AxMSWinsockLib.AxWinsock
'UPGRADE_ISSUE: Unload Socket was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="875EBAD7-D704-4539-9969-BC7DBDAA62A2"'
Socket.Dispose()
End If
Next Socket
'Object netProxy may not be destroyed until it is garbage collected.
netProxy = Nothing
'Object ServerConnection may not be destroyed until it is garbage collected.
ServerConnection = Nothing
'Object ClientConnection may not be destroyed until it is garbage collected.
ClientConnection = Nothing
End Sub
Private Sub lstLog_MouseDown(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.MouseEventArgs) Handles lstLog.MouseDown
Dim Button As Short = eventArgs.Button \ &H100000
Dim Shift As Short = System.Windows.Forms.Control.ModifierKeys \ &H10000
Dim X As Single = VB6.PixelsToTwipsX(eventArgs.X)
Dim Y As Single = VB6.PixelsToTwipsY(eventArgs.Y)
If Button = VB6.MouseButtonConstants.RightButton Then
'PopupMenu(mnuLog, vbPopupMenuRightButton, X + 240, Y + 1060)
End If
End Sub
Public Sub mnuClearHeader_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mnuClearHeader.Click
txtRequest.Text = ""
txtResponse.Text = ""
End Sub
Public Sub mnuClearLog_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mnuClearLog.Click
lstLog.Items.Clear()
End Sub
Private Sub sckClient_CloseEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles sckClient.CloseEvent
Dim Index As Short = sckClient.GetIndex(eventSender)
InitializeSocket(sckClient(Index))
'UPGRADE_WARNING: Couldn't resolve default property of object ClientConnection().ClearBuffer. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
ClientConnection.Item(Index).ClearBuffer()
End Sub
Private Sub sckClient_ConnectEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles sckClient.ConnectEvent
Dim Index As Short = sckClient.GetIndex(eventSender)
Dim vData As String
Dim dataheader As String
'dataheader = "x-host:web.blackberry.com%2f%3a%0a@ HTTP/1.1" + vbCrLf + "bughost" + vbCrLf + vbCrLf + vbCrLf
'send the data request when connected
'UPGRADE_NOTE: State was upgraded to CtlState. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
If sckClient(Index).CtlState = MSWinsockLib.StateConstants.sckConnected Then
'UPGRADE_WARNING: Couldn't resolve default property of object ClientConnection().SendBuffer. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
vData = ClientConnection.Item(Index).SendBuffer
If Len(vData) <> 0 Then
'UPGRADE_WARNING: Couldn't resolve default property of object ClientConnection().SendBuffer. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
vData = ClientConnection.Item(Index).SendBuffer.GetString
SendDataTo(sckClient(Index), dataheader & vData)
SendToLog("Connected to Server " & sckClient(Index).RemoteHostIP & ":" & sckClient(Index).RemotePort)
If DEBUG_MODE Then Debug.Print("send to server " & vbCrLf & vData)
End If
End If
End Sub
Private Sub sckClient_DataArrival(ByVal eventSender As System.Object, ByVal eventArgs As AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent) Handles sckClient.DataArrival
Dim Index As Short = sckClient.GetIndex(eventSender)
Dim vData As String
Dim lpos As Integer
Dim Header, Data As String
Dim data1 As String
data1 = "HTTP/1.1 200 OK" & "vbCrLf+ vbCrLf +vbCrLf + vbCrLf + vbCrLf"
'UPGRADE_NOTE: State was upgraded to CtlState. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
If Index <> 0 And sckClient(Index).CtlState = MSWinsockLib.StateConstants.sckConnected Then
SendToLog("Receive data from server " & sckClient(Index).RemoteHostIP & ":" & sckClient(Index).RemotePort & " size: " & eventArgs.bytesTotal & " bytes")
'ok, this is rather tricky but here goes...
'first we append the data to a buffer in serverconnection which it'll keep in seperate buffer
'until the header is received.
'when the header has been received then we send the header buffer to the sent buffer
'which will be sent by the timer,
'and we set the connected flag to true to tell the
'append function to directly put the data in the sent buffer.
sckClient(Index).GetData(vData)
'UPGRADE_WARNING: Couldn't resolve default property of object ServerConnection().Append. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
ServerConnection.Item(Index).Append(vData)
'UPGRADE_WARNING: Couldn't resolve default property of object ServerConnection(Index).Connected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
'UPGRADE_WARNING: Couldn't resolve default property of object ServerConnection(Index).HeaderReceived. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
If ServerConnection.Item(Index).HeaderReceived And Not ServerConnection.Item(Index).Connected Then
'UPGRADE_WARNING: Couldn't resolve default property of object ServerConnection(Index).Header. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
If DEBUG_MODE Then Debug.Print("received from server " & vbCrLf & ServerConnection.Item(Index).Header)
'UPGRADE_WARNING: Couldn't resolve default property of object ServerConnection().Header. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
Header = FilterResponseHeader(ServerConnection.Item(Index).Header)
Header = data1 & vbCrLf & Header
'UPGRADE_WARNING: Couldn't resolve default property of object ServerConnection(Index).SendBuffer. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
'UPGRADE_WARNING: Couldn't resolve default property of object ServerConnection().Data. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
ServerConnection.Item(Index).SendBuffer = Header & vbCrLf & ServerConnection.Item(Index).Data
'UPGRADE_WARNING: Couldn't resolve default property of object ServerConnection(Index).DataSent. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
'UPGRADE_WARNING: Couldn't resolve default property of object ServerConnection().Data. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
'UPGRADE_WARNING: Couldn't resolve default property of object ServerConnection().DataSent. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
ServerConnection.Item(Index).DataSent = ServerConnection.Item(Index).DataSent + Len(ServerConnection.Item(Index).Data)
'UPGRADE_WARNING: Couldn't resolve default property of object ServerConnection().Connected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
ServerConnection.Item(Index).Connected = True
SendResponseHeader("Socket " & Index & " :" & vbCrLf & Header)
If DEBUG_MODE Then Debug.Print("send to client buffer " & vbCrLf & Header)
End If
End If
End Sub
Private Sub sckClient_Error(ByVal eventSender As System.Object, ByVal eventArgs As AxMSWinsockLib.DMSWinsockControlEvents_ErrorEvent) Handles sckClient.Error
Dim Index As Short = sckClient.GetIndex(eventSender)
InitializeSocket(sckServer(Index))
If Index <> 0 Then
'UPGRADE_WARNING: Couldn't resolve default property of object ClientConnection().ClearBuffer. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
ClientConnection.Item(Index).ClearBuffer()
End If
InitializeSocket(sckClient(Index))
If Index <> 0 Then
'UPGRADE_WARNING: Couldn't resolve default property of object ServerConnection().ClearBuffer. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
ServerConnection.Item(Index).ClearBuffer()
End If
End Sub
Private Sub sckServer_CloseEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles sckServer.CloseEvent
Dim Index As Short = sckServer.GetIndex(eventSender)
CloseSocket(Index)
End Sub
Private Sub sckServer_ConnectionRequest(ByVal eventSender As System.Object, ByVal eventArgs As AxMSWinsockLib.DMSWinsockControlEvents_ConnectionRequestEvent) Handles sckServer.ConnectionRequest
Dim Index As Short = sckServer.GetIndex(eventSender)
Dim i, ActiveConnection As Integer
Dim ReceivingSocket As AxMSWinsockLib.AxWinsock
If Index = 0 Then
'count the active connection
ActiveConnection = 0
For i = 0 To sckServer.Count - 1
'UPGRADE_NOTE: State was upgraded to CtlState. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
If i <> 0 Then If sckServer(i).CtlState <> MSWinsockLib.StateConstants.sckClosed Then ActiveConnection = ActiveConnection + 1
Next i
'receiving connection
ReceivingSocket = AvailableSocket
ReceivingSocket.Accept(eventArgs.requestID)
'checking the maximum connection
If ActiveConnection < MaximumConnection Then
SendToLog("Accept connection request from client " & AvailableSocket.RemoteHostIP & ":" & ReceivingSocket.RemotePort)
Else
'UPGRADE_ISSUE: VBControlExtender property ReceivingSocket.Index was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
'UPGRADE_WARNING: Couldn't resolve default property of object ServerConnection().Rejected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
ServerConnection.Item(ReceivingSocket.Index).Rejected = True
SendToLog("Maximum connection reached, Connection request from client " & ReceivingSocket.RemoteHostIP & ":" & ReceivingSocket.RemotePort & " rejected")
End If
End If
'UPGRADE_NOTE: Object ReceivingSocket may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
ReceivingSocket = Nothing
End Sub
Private Sub sckServer_DataArrival(ByVal eventSender As System.Object, ByVal eventArgs As AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent) Handles sckServer.DataArrival
Dim Index As Short = sckServer.GetIndex(eventSender)
Dim i, lpos As Integer
Dim vData As String
Static Blocking As Boolean
Dim Header As String
'UPGRADE_NOTE: State was upgraded to CtlState. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
If Index <> 0 And sckServer(Index).CtlState = MSWinsockLib.StateConstants.sckConnected Then
SendToLog("Receive data from client " & sckServer(Index).RemoteHostIP & ":" & sckServer(Index).RemotePort & " size: " & eventArgs.bytesTotal & " bytes")
sckServer(Index).GetData(vData)
'UPGRADE_WARNING: Couldn't resolve default property of object ClientConnection().Append. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
ClientConnection.Item(Index).Append(vData)
'UPGRADE_WARNING: Couldn't resolve default property of object ClientConnection(Index).Connected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
'UPGRADE_WARNING: Couldn't resolve default property of object ClientConnection(Index).HeaderReceived. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
If ClientConnection.Item(Index).HeaderReceived And Not ClientConnection.Item(Index).Connected Then
'if header received then check the authorization status,
'if rejected because maximum connection reached then we send the rejected form
'if authorization is needed we send the request for password form.
'UPGRADE_WARNING: Couldn't resolve default property of object ClientConnection(Index).Header. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
If DEBUG_MODE Then Debug.Print("received from client " & vbCrLf & ClientConnection.Item(Index).Header)
'UPGRADE_WARNING: Couldn't resolve default property of object ServerConnection(Index).Rejected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
If ServerConnection.Item(Index).Rejected Then
'maximum connection reached
Header = GenerateHTMLForm(modHTML.ENUM_FORM_TYPE.ftRejected)
'UPGRADE_WARNING: Couldn't resolve default property of object ServerConnection().SendBuffer. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
ServerConnection.Item(Index).SendBuffer = Header
SendResponseHeader("Socket " & Index & " :" & vbCrLf & Header)
System.Windows.Forms.Application.DoEvents()
CloseSocket(Index)
If DEBUG_MODE Then Debug.Print("send to client buffer " & vbCrLf & Header)
'UPGRADE_WARNING: Couldn't resolve default property of object ServerConnection(Index).AuthorizeUser. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
ElseIf Not ServerConnection.Item(Index).AuthorizeUser Then
'UPGRADE_WARNING: Couldn't resolve default property of object ServerConnection(Index).AuthorizeUser. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
'UPGRADE_WARNING: Couldn't resolve default property of object ClientConnection(Index).Header. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
ServerConnection.Item(Index).AuthorizeUser = CheckCredential(sckServer(Index), ClientConnection.Item(Index).Header)
'UPGRADE_WARNING: Couldn't resolve default property of object ServerConnection(Index).AuthorizeUser. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
If Not ServerConnection.Item(Index).AuthorizeUser Then
'not yet authorized
Header = GenerateHTMLForm(modHTML.ENUM_FORM_TYPE.ftAuthenticate)
'UPGRADE_WARNING: Couldn't resolve default property of object ServerConnection().SendBuffer. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
ServerConnection.Item(Index).SendBuffer = Header
'UPGRADE_WARNING: Couldn't resolve default property of object ClientConnection().ClearBuffer. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
ClientConnection.Item(Index).ClearBuffer()
SendResponseHeader("Socket " & Index & " :" & vbCrLf & Header)
If DEBUG_MODE Then Debug.Print("send to client buffer " & vbCrLf & Header)
'UPGRADE_WARNING: Couldn't resolve default property of object ClientConnection().Header. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
ElseIf VB.Left(ClientConnection.Item(Index).Header, 7) = "OPTIONS" Then
'this form used when the browser sent OPTION Method (Opera)
'i don't know what it's used for... but we just send them not found form
Header = GenerateHTMLForm(modHTML.ENUM_FORM_TYPE.ftNotFound)
'UPGRADE_WARNING: Couldn't resolve default property of object ServerConnection().SendBuffer. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
ServerConnection.Item(Index).SendBuffer = Header
SendResponseHeader("Socket " & Index & " :" & vbCrLf & Header)
System.Windows.Forms.Application.DoEvents()
CloseSocket(Index)
Else
'authorized
InitializeSocket(sckClient(Index))
'UPGRADE_WARNING: Couldn't resolve default property of object ClientConnection().Header. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
Header = FilterRequestHeader(ClientConnection.Item(Index).Header)
'UPGRADE_WARNING: Couldn't resolve default property of object ClientConnection(Index).SendBuffer. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
'UPGRADE_WARNING: Couldn't resolve default property of object ClientConnection().Data. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
ClientConnection.Item(Index).SendBuffer = Header & vbCrLf & ClientConnection.Item(Index).Data
'UPGRADE_WARNING: Couldn't resolve default property of object ClientConnection(Index).DataSent. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
'UPGRADE_WARNING: Couldn't resolve default property of object ClientConnection().Data. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
'UPGRADE_WARNING: Couldn't resolve default property of object ClientConnection().DataSent. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
ClientConnection.Item(Index).DataSent = ClientConnection.Item(Index).DataSent + Len(ClientConnection.Item(Index).Data)
'UPGRADE_WARNING: Couldn't resolve default property of object ClientConnection().Connected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
ClientConnection.Item(Index).Connected = True
SendRequestHeader("Socket " & Index & " :" & vbCrLf & Header)
AddConnectionStatistic(sckServer(Index))
If DEBUG_MODE Then Debug.Print("send to server buffer " & vbCrLf & Header)
End If
'UPGRADE_WARNING: Couldn't resolve default property of object ClientConnection().Header. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
ElseIf VB.Left(ClientConnection.Item(Index).Header, 7) = "OPTIONS" Then
'this form used when the browser sent OPTION Method (Opera)
'i don't know what it's used for... but we just send them not found form
Header = GenerateHTMLForm(modHTML.ENUM_FORM_TYPE.ftNotFound)
'UPGRADE_WARNING: Couldn't resolve default property of object ServerConnection().SendBuffer. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
ServerConnection.Item(Index).SendBuffer = Header
SendResponseHeader("Socket " & Index & " :" & vbCrLf & Header)
System.Windows.Forms.Application.DoEvents()
CloseSocket(Index)
Else
'ok
InitializeSocket(sckClient(Index))
'UPGRADE_WARNING: Couldn't resolve default property of object ClientConnection().Header. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
Header = FilterRequestHeader(ClientConnection.Item(Index).Header)
'UPGRADE_WARNING: Couldn't resolve default property of object ClientConnection(Index).SendBuffer. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
'UPGRADE_WARNING: Couldn't resolve default property of object ClientConnection().Data. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
ClientConnection.Item(Index).SendBuffer = Header & vbCrLf & ClientConnection.Item(Index).Data
'UPGRADE_WARNING: Couldn't resolve default property of object ClientConnection(Index).DataSent. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
'UPGRADE_WARNING: Couldn't resolve default property of object ClientConnection().Data. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
'UPGRADE_WARNING: Couldn't resolve default property of object ClientConnection().DataSent. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
ClientConnection.Item(Index).DataSent = ClientConnection.Item(Index).DataSent + Len(ClientConnection.Item(Index).Data)
'UPGRADE_WARNING: Couldn't resolve default property of object ClientConnection().Connected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
ClientConnection.Item(Index).Connected = True
SendRequestHeader("Socket " & Index & " :" & vbCrLf & Header)
AddConnectionStatistic(sckServer(Index))
If DEBUG_MODE Then Debug.Print("send to server buffer " & vbCrLf & Header)
End If
End If
End If
End Sub
Private Sub sckServer_Error(ByVal eventSender As System.Object, ByVal eventArgs As AxMSWinsockLib.DMSWinsockControlEvents_ErrorEvent) Handles sckServer.Error
Dim Index As Short = sckServer.GetIndex(eventSender)
CloseSocket(Index)
End Sub
Private Function AvailableSocket() As AxMSWinsockLib.AxWinsock
Dim Socket As AxMSWinsockLib.AxWinsock
'seach socket array for closed connection
For Each Socket In sckServer
System.Windows.Forms.Application.DoEvents()
'UPGRADE_NOTE: State was upgraded to CtlState. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
If Socket.CtlState = MSWinsockLib.StateConstants.sckClosed Then
'UPGRADE_ISSUE: VBControlExtender property Socket.Index was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
'UPGRADE_WARNING: Couldn't resolve default property of object ServerConnection().ClearBuffer. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
ServerConnection.Item(Socket.Index).ClearBuffer()
'UPGRADE_ISSUE: VBControlExtender property Socket.Index was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
'UPGRADE_WARNING: Couldn't resolve default property of object ClientConnection().ClearBuffer. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
ClientConnection.Item(Socket.Index).ClearBuffer()
AvailableSocket = Socket
Exit Function
End If
Next Socket
'if there aren't any closed connection we load a new socket to received the connection request
AvailableSocket = AddNewConnection
End Function
Private Function AddNewConnection() As AxMSWinsockLib.AxWinsock
Dim ServerData As New CBuffer
Dim ClientData As New CBuffer
Dim NewSocket As Integer
NewSocket = sckServer.Count
sckServer.Load(NewSocket)
tmrServer.Load(NewSocket)
ServerData.HeaderType = CBuffer.ENUM_HEADER_TYPE.htResponse
ServerData.ClearBuffer()
ServerConnection.Add(ServerData, Chr(NewSocket))
sckClient.Load(NewSocket)
tmrClient.Load(NewSocket)
ClientData.HeaderType = CBuffer.ENUM_HEADER_TYPE.htRequest
ClientData.ClearBuffer()
ClientConnection.Add(ClientData, Chr(NewSocket))
AddNewConnection = sckServer(NewSocket)
End Function
Private Sub sckServer_SendComplete(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles sckServer.SendComplete
Dim Index As Short = sckServer.GetIndex(eventSender)
'we close both connection when the requested data has been sent to the browser.
'UPGRADE_WARNING: Couldn't resolve default property of object ServerConnection(Index).ResponseHeader. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
'UPGRADE_WARNING: Couldn't resolve default property of object ServerConnection(Index).DataSent. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
If ServerConnection.Item(Index).DataSent >= ServerConnection.Item(Index).ResponseHeader.Length Then
'UPGRADE_WARNING: Couldn't resolve default property of object ServerConnection().ResponseHeader. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
If ServerConnection.Item(Index).ResponseHeader.GetHeader("Content-Length") <> "" Then
'tmpString = AddHttpHeader(tmpString, "Host", "mmsc.indosat.com")
'UPGRADE_WARNING: Couldn't resolve default property of object ServerConnection().SendBuffer. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
'UPGRADE_NOTE: State was upgraded to CtlState. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
If sckClient(Index).CtlState <> MSWinsockLib.StateConstants.sckConnected And Len(ServerConnection.Item(Index).SendBuffer) = 0 Then
CloseSocket(Index)
End If
End If
End If
End Sub
Private Sub tmrClient_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles tmrClient.Tick
Dim Index As Short = tmrClient.GetIndex(eventSender)
Dim i As Integer
Dim vData As String
'timer to send the data to host server/proxy server if there are any data in the sent buffer
If Index <> 0 Then
i = Index
'UPGRADE_WARNING: Couldn't resolve default property of object ClientConnection().SendBuffer. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
vData = ClientConnection.Item(i).SendBuffer
If Len(vData) <> 0 Then
'UPGRADE_NOTE: State was upgraded to CtlState. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
If sckClient(i).CtlState <> MSWinsockLib.StateConstants.sckConnected And sckClient(i).CtlState <> MSWinsockLib.StateConstants.sckConnecting Then
'UPGRADE_WARNING: Couldn't resolve default property of object ClientConnection(i). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
ConnectSocket(sckClient(i), ClientConnection.Item(i))
'UPGRADE_NOTE: State was upgraded to CtlState. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
ElseIf sckClient(i).CtlState = MSWinsockLib.StateConstants.sckConnected And Len(vData) <> 0 Then
'UPGRADE_WARNING: Couldn't resolve default property of object ClientConnection().SendBuffer. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
vData = ClientConnection.Item(i).SendBuffer.GetString
SendDataTo(sckClient(i), vData)
If DEBUG_MODE Then Debug.Print("send to server " & vbCrLf & vData)
End If
End If
End If
End Sub
Private Sub SendDataTo(ByRef Socket As AxMSWinsockLib.AxWinsock, ByRef vData As String)
'send data to specified socket
Socket.SendData(vData)
SendToLog("Sending data to " & Socket.RemoteHostIP & ":" & Socket.RemotePort & " Size:" & Len(vData))
End Sub
Private Sub ConnectSocket(ByRef Socket As AxMSWinsockLib.AxWinsock, ByRef BufferConnection As CBuffer)
Dim vProxyServer As String
Dim vProxyPort As Integer
On Error GoTo errHandler
'connecting to host server or proxy server
If UseProxy Then
vProxyServer = netProxy.Server
vProxyPort = netProxy.Port
Else
vProxyServer = BufferConnection.Server
vProxyPort = BufferConnection.Port
End If
Socket.Connect(vProxyServer, vProxyPort)
System.Windows.Forms.Application.DoEvents()
SendToLog("Connecting to server " & vProxyServer & ":" & vProxyPort)
Exit Sub
errHandler:
End Sub
Private Sub tmrServer_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles tmrServer.Tick
Dim Index As Short = tmrServer.GetIndex(eventSender)
Dim i As Integer
Dim vData As String
If Index <> 0 Then
i = Index
'UPGRADE_NOTE: State was upgraded to CtlState. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
If sckServer(i).CtlState = MSWinsockLib.StateConstants.sckConnected Then
'UPGRADE_WARNING: Couldn't resolve default property of object ServerConnection().SendBuffer. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
vData = ServerConnection.Item(i).SendBuffer
If Len(vData) <> 0 Then
'UPGRADE_WARNING: Couldn't resolve default property of object ServerConnection().SendBuffer. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
vData = ServerConnection.Item(i).SendBuffer.GetString
SendDataTo(sckServer(i), vData)
If DEBUG_MODE Then Debug.Print("send to client " & vbCrLf & vData)
End If
End If
End If
End Sub
Private Sub CloseSocket(ByRef Index As Short)
'close both socket connection (client and server)
InitializeSocket(sckClient(Index))
If Index <> 0 Then
'UPGRADE_WARNING: Couldn't resolve default property of object ServerConnection().ClearBuffer. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
ServerConnection.Item(Index).ClearBuffer()
End If
InitializeSocket(sckServer(Index))
If Index <> 0 Then
'UPGRADE_WARNING: Couldn't resolve default property of object ClientConnection().ClearBuffer. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
ClientConnection.Item(Index).ClearBuffer()
End If
End Sub
Private Sub SendRequestHeader(ByRef Message As String)
'showing the request header to textbox
If Len(txtRequest.Text) > 16384 Then
txtRequest.Text = ""
End If
txtRequest.Text = txtRequest.Text & Message & vbCrLf
End Sub
Private Sub SendResponseHeader(ByRef Message As String)
'showing the response header to textbox
If Len(txtResponse.Text) > 16384 Then
txtResponse.Text = ""
End If
txtResponse.Text = txtResponse.Text & Message & vbCrLf
End Sub
Private Sub InitializeGrid()
'init statistic grid
With flxStatistic
.Clear()
.Rows = 1
.Cols = 4
.set_ColAlignment(0, MSFlexGridLib.AlignmentSettings.flexAlignLeftCenter)
.set_TextMatrix(0, 0, "No.")
.set_TextMatrix(0, 1, "IP Address")
.set_TextMatrix(0, 2, "Host Name")
.set_TextMatrix(0, 3, "Connection")
End With
End Sub
End Class