Note that there are some explanatory texts on larger screens.

plurals
  1. POPython Simple TCP relay
    text
    copied!<p>I'm trying to build a simple TCP relay that accepts multiple client connection.</p> <pre><code>Client1 --&gt; TCPrelay1 --&gt; RealServer1 --&gt; TCPrelay1 --&gt; Client1 Client2 --&gt; TCPrelay1 --&gt; RealServer1 --&gt; TCPrelay1 --&gt; Client2 Client3 --&gt; TCPrelay1 --&gt; RealServer1 --&gt; TCPrelay1 --&gt; Client3 </code></pre> <p>Something in that matter. No limit really on how many clients</p> <hr> <p>I found a UDP relay script <a href="https://github.com/EtiennePerot/misc-scripts/blob/master/udp-relay.py" rel="nofollow">here</a>.</p> <p>I tried to modify it to TCP. I'm really new to python sockets. So what could be wrong with my code? Nothing is happening. And its not relaying.</p> <pre><code>#SOCK_STREAM --TCP localPort = 5000 remotePort = 5000 #SV remoteHost = "xxxxx" try: localPort = int(localPort) except: fail('Invalid port number: ' + str(localPort)) try: remotePort = int(remotePort) except: fail('Invalid port number: ' + str(remotePort)) try: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(('', localPort)) s.listen(1) except: fail('Failed to bind on port ' + str(localPort)) knownClient = None while True: conn, addr = s.accept() conn2, addr2 = s.connect((remoteHost, remotePort)) data = connection.recv(1024) if knownClient is None: knownClient = addr if addr == knownClient: s.sendall(data) print "Sent : " + ":".join("{0:X}".format(ord(c)) for c in data) else: s.sendall(data) print "Received : " + ":".join("{0:X}".format(ord(c)) for c in data) </code></pre> <hr> <p>[disregard]<br> Did a few research and found this logic at another SO question:</p> <pre><code>import select def fromAtoB(A, B): r, w = select.select([A], [B], []) if not r: select.select([A], [], []) elif not w: select.select([], [B], []) B.sendall(A.recv(4096)) </code></pre> <p>But I'm still trying to understand how to implement it.</p>
 

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