Jump to content
Sign in to follow this  

Why my web proxy doen't fully load google.com? It loads half of it and then stops loading.

Recommended Posts


I am trying to make proxy, but it freezes when google is loading. I am trying to make that proxy work so that when you connect to local host, you see google.com instead. So When I connect to Page loading indicator gets to half and then it stops moving, which means that page stops loading.

I cant find out reason why page stops loading at half. Why don't this page fully load?. Looks like connection freezes after X packets. Connection freezes where it says: To TCP Client:0x48.....

Does anyone have any idea about what might cause this?

#include <Array.au3>
#include <Constants.au3>
Dim $array[100][2], $f, $incorrect, $user[100], $ReplySocet[100], $UdpSocket, $u, $UDPReplySocet
$GoiogleIP = ""
$WebPort = 80

$remoteIP = $GoiogleIP
$Port = $WebPort

;Start up TCP and UDP

$MainSocket = TCPListen("", $Port);Create a socket listening for an incoming connection.
If $MainSocket = -1 Then Exit ;Exit on errors

While 1
    For $r = 0 To UBound($array) - 1;Loop trought array, to see wether anyconnection handle has received any packets
        If $array[$r][0] <> "" Then;Check if current array element is connection handle
            $recv = TCPRecv($array[$r][0], 4096, 1)
            If $recv <> "" Then; check is client sent anything
                ConsoleWrite("To TCP Server:" & $recv & @CRLF)
                $ans = getServer($recv, $r);Forward Packet from client to server
                ;return value ($ans) is Server's reply
                If Not @error Then;If not any errors (@error is set by getServer if server doesnt respond in time)
                    ConsoleWrite("To TCP Client:" & $ans & @CRLF)
                    TCPSend($array[$r][0], $ans);Send answer sent by server to client
                Else;If server did not respond
                    ConsoleWrite("To TCP ERROR:" & @CRLF)
        If IsArray($UdpSocket) <> "" Then;If UDP connection exists
            $recv = UDPRecv($UdpSocket, 4096, 1)
            If $recv <> "" Then;Check if any packets sent by UDP server
                ConsoleWrite("To UDP Server:" & $recv & @CRLF)
                $ans = getUDPServer($recv);Forward client's UDP packet to server and
                ;return server's reply
                If Not @error Then; If server responded
                    ConsoleWrite("To UDP Client:" & $ans & @CRLF)
                    UDPSend($UdpSocket, Binary($ans));Forward server's response to client
                Else;If server did not respond
                    ConsoleWrite("To UDP ERROR:" & @CRLF)
    newTCPclient() ;Accept new TCP Client
    newUDPclient() ;Accept new UDP Client

Func newTCPclient()
    $ConnectedSocket = TCPAccept($MainSocket) ;$ConnectedSocket's value is Connection handle
    If $ConnectedSocket <> -1 Then
        ConsoleWrite("New TCP connection" & @CRLF)
        ConsoleWrite("Socet: "&$ConnectedSocket & @CRLF)
        $array[$f][0] = $ConnectedSocket; f'th element of array is connection handle
        $f += 1;Increase f by 1 so, when new TCP connection is created, new array element
        ;will get connection handle.
        ;This way we can support multiple connections.
EndFunc   ;==>newTCPclient

Func newUDPclient()
    $socket = UDPBind(@IPAddress1, 6112);$socket is array contains socket handle,ip, port
    ;$socket can be used to send/recv UDP
    If $socket[1] <> "" Then
        ConsoleWrite("New UDP connection" & @CRLF)
        ConsoleWrite("Socet: "&$socket[1] & @CRLF)
        $UdpSocket = $socket
;~      $u += 1
EndFunc   ;==>newUDPclient

Func getServer($recv, $r)
    If $ReplySocet[$r] = "" Then; If connection with server not created, create new
        $ReplySocet[$r] = TCPConnect($remoteIP, $Port)
    TCPSend($ReplySocet[$r], $recv);Send packet we got from Client to server
    $timer = TimerInit();Start Timer to avoid overhead time loss
    While 1
        If TimerDiff($timer) > 500 Then ;If server doent respond in  500 ms, return empty string and set error 1
        $reply = TCPRecv($ReplySocet[$r], 4096, 1) ;Get Server reply for packet
        If $reply <> "" Then Return $reply; If server replied, Return server's reply.
EndFunc   ;==>getServer

Func getUDPServer($recv)
    If $UDPReplySocet = "" Then ;If UDP connection between Server doesnt't exist
        $UDPReplySocet = UDPOpen($remoteIP, $Port); Create new UDP connection
        ConsoleWrite("UDP Remote Connection Started:"&$UDPReplySocet[1]&@CRLF)
    UDPSend($UDPReplySocet, $recv);Forward packet received from client to server
    If @error Then MsgBox(0,0,"ERROR");Notify if sending packet failed.
    $timer = TimerInit();Start timer
    While 1
        If TimerDiff($timer) > 500 Then; If no answer in 500 ms
            SetError(1);set @error so we wont send empty packet to client.
        $reply = UDPRecv($UDPReplySocet, 4096, 1)
        If $reply <> "" Then Return $reply;If UDP server respnded, Return server's response.
EndFunc   ;==>getUDPServer
Edited by E1M1


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.