Shark lo he visto bien..
publico el codigo, para que me ayudeis stabilisando lo..
es codigo abierto e gran parte cogio del www.
scimsoft es mi empresa (holandés). Pero hago ya menos por el www. Mas programacion w32
aqui debajo grande parte del codigo...
(falta mucho un 'thread' e pareces que necesitamos de hacer un tiempo de espero porque despues mucho nuevo winsock objectos no conectes mas de nuevo...)
Option Explicit
Dim s(255) As String
Dim h(255) As String
Dim p(255) As String
Dim i As Integer
Private Sub cmdStart_Click()
If cmdStart.Caption = "Start" Then
wsTCP(0).LocalPort = txtPort
wsTCP(0).Listen
lblStatus = "Running..."
cmdStart.Caption = "Stop"
Else
cmdStart.Caption = "Start"
wsTCP(0).Close
lblStatus = "Stopped"
End If
End Sub
Private Sub Command1_Click(Index As Integer)
WriteRegistry HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", ValDWord, "1"
WriteRegistry HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyServer", ValString, "http=localhost:" & txtPort.Text
End Sub
Private Sub Command2_Click(Index As Integer)
WriteRegistry HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", ValDWord, "0"
End Sub
Private Sub wsProxy_Close(Index As Integer)
On Error Resume Next
Unload wsProxy(Index)
wsTCP(Index).SendData p(Index)
End Sub
Private Sub wsProxy_Connect(Index As Integer)
Dim temp As String
If InStr(UCase(s(Index)), "ACCEPT") > 0 Then
'temp = insertString("Pragma: no-cache" & vbNewLine & "Cache-control: no-cache" & vbNewLine, s(Index), InStr(UCase(s(Index)), "ACCEPT") - 1)
temp = insertString("Cache-Control: max-age=0" & vbNewLine, s(Index), InStr(UCase(s(Index)), "ACCEPT") - 1)
Debug.Print "ok"
End If
'temp = Replace(s(Index), "Proxy-Connection: Keep-Alive", "Pragma: no-cache" & vbNewLine & "Cache-control: no-cache" & vbNewLine & "Proxy-Connection: Keep-Alive", , , vbBinaryCompare)
'temp = s(Index)
wsProxy(Index).SendData temp
' Debug.Print Index
Debug.Print temp
End Sub
Private Sub wsProxy_DataArrival(Index As Integer, ByVal bytesTotal As Long)
wsProxy(Index).GetData h(Index)
'Debug.Print "(" & Index & ") " & h(Index)
p(Index) = p(Index) & h(Index)
End Sub
Private Sub wsProxy_Error(Index As Integer, ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
'Debug.Print "(" & Index & ") Error Proxy " & Number & ": " & Description
Unload wsProxy(Index)
End Sub
Private Sub wsTCP_Close(Index As Integer)
Unload wsTCP(Index)
End Sub
Private Sub wsTCP_ConnectionRequest(Index As Integer, ByVal requestID As Long)
i = i + 1
Load wsTCP(i)
Load wsProxy(i)
wsTCP(i).Accept requestID
Debug.Print requestID
End Sub
Private Sub wsTCP_DataArrival(Index As Integer, ByVal bytesTotal As Long)
wsTCP(Index).GetData s(Index)
'Debug.Print "(" & Index & ") " & s(Index)
Dim strHost As String, iPort As Integer
iPort = 80
If InStr(UCase(s(Index)), "GET ") > 0 Then
strHost = Mid(s(Index), InStr(UCase(s(Index)), "GET ") + 4)
ElseIf InStr(UCase(s(Index)), "PUT ") > 0 Then
strHost = Mid(s(Index), InStr(UCase(s(Index)), "PUT ") + 4)
Else
wsTCP(Index).SendData "Mailformed HTTP request"
Exit Sub
End If
strHost = Left(strHost, InStr(strHost, " ") - 1)
If InStr(strHost, "://") 0 Then strHost = Mid(strHost, InStr(strHost, "://") + 3)
If InStr(strHost, ":") 0 Then
iPort = Val(Mid(strHost, InStr(strHost, ":") + 1))
strHost = Left(strHost, InStr(strHost, ":") - 1)
End If
If InStr(strHost, "/") > 0 Then strHost = Left(strHost, InStr(strHost, "/") - 1)
'Debug.Print strHost
'Debug.Print Index & " " & iPort
Debug.Print wsProxy.LBound
If wsProxy.Count > 4 Then
Debug.Print wsProxy.Count
DoEvents
Else
With wsProxy(Index)
.RemoteHost = strHost
.RemotePort = iPort
.Connect
End With
End If
End Sub
Private Sub wsTCP_Error(Index As Integer, ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
'Debug.Print "(" & Index & ") Error TCP" & Number & ": " & Description
Unload wsTCP(Index)
End Sub
Private Sub wsTCP_SendComplete(Index As Integer)
wsTCP(Index).Close
End Sub