Note that there are some explanatory texts on larger screens.

plurals
  1. POPython TCP & UDP proxy/relay
    primarykey
    data
    text
    <p>OS: CentOS<br> Python: 2.4 and 2.7</p> <p>I'm trying to build a relay or proxy for both TCP and UDP traffic for my applications.<br> My setup is app1 verifies app2 is online by constantly sending UDP packets.<br> Once app1 verifies that app2 is online, it will then send app2 data packets via TCP protocol.</p> <p>This is my code so far:</p> <pre><code>#------------------------------------- #SOCK_DGRAM --UDP u_localPort = 20006 u_remotePort = 20006 u_remoteHost = "x.x.x.x" u_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) u_sock.bind(('', u_localPort)) u_knownClient = None u_knownServer = (u_remoteHost, u_remotePort) #------------------------------------- #------------------------------------- #SOCK_STREAM --TCP t_localPort = 10006 t_remotePort = 10006 t_remoteHost = "x.x.x.x" #client c_tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM) c_tcp.connect((t_remoteHost, t_remotePort)) #server s_tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s_tcp.bind(('', u_localPort)) s_tcp.listen(1) conn, addr = s_tcp.accept() #------------------------------------- while True: u_data, u_addr = u_sock.recvfrom(4096) if u_knownClient is None: u_knownClient = u_addr if u_addr == u_knownClient: u_sock.sendto(u_data, u_knownServer) else: u_sock.sendto(u_data, u_knownClient) data = conn.recv(1024) if not data: break print "received data:", data c_tcp.send(data) # echo </code></pre> <p>With this code the UDP data seems to be relaying properly. But the TCP isn't. What could be wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload