Search code examples
pythonhtmltcpudppython-sockets

How to proxy UDP packets?


On Server side, i receive payload from web site, and send it trough my client-server connection. Client receives html page, processes it using web browser ( google chrome ), and i receive a page... But without any pictures.
Server code -->

    f = socket.socket()
    f.settimeout(1)
    f.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    try:
        a = random.randint(2000,9999)
        f.bind(("0.0.0.0", a))
    except:
        a = random.randint(2000,9999)
        f.bind(("0.0.0.0", a))
    f.connect((url, 80))
    url2 = url.encode('utf-8')
    f.sendall(b"GET / HTTP/1.1\r\nHost:"+url2+b"\r\n\r\n")
    while True:
        try:
            data = f.recv(4096)
            #print(data)
            data = data.decode('utf-8')
            data = data.encode('utf-8')
            client_connection.send(data)
        except:
            break
    f.setblocking(False)
    f.close()

Must i listen for udp traffic also?
like --> data_udp = f.recv.udp(4096)
Or what do i do wrong?


Solution

  • Nope, http header says if image is transported, just needed to

    1. check if image is transported
    2. if it is image, do not encode-decode it, it will make troubles.