Skip to content

Instantly share code, notes, and snippets.

@Motoma
Created September 13, 2011 23:27
Show Gist options
  • Save Motoma/1215469 to your computer and use it in GitHub Desktop.
Save Motoma/1215469 to your computer and use it in GitHub Desktop.
running = False
try:
# In this example, we bridge over port 18293
listener = socket.socket()
listener.bind(('0.0.0.0', 18293))
listener.listen(1)
bridge_client = listener.accept()[0]
listener.close()
print("Bridge Client Connected.")
# We will accept a single incoming connection on port 3306
listener = socket.socket()
listener.bind(('0.0.0.0', 8080))
listener.listen(1)
client = listener.accept()[0]
listener.close()
print("Client Connected")
running = True
except: pass
while running:
try:
rlist = select.select([bridge_client, client], [], [])[0]
if bridge_client in rlist:
buf = bridge_client.recv(4096)
if len(buf) == 0:
print("Bridge Client Disconnected.")
running = False
client.send(buf)
if client in rlist:
buf = client.recv(4096)
if len(buf) == 0:
print("Client Disconnected.")
running = False
bridge_client.send(buf)
except:
pass
try: client.close()
except: pass
try: bridge_client.close()
except: pass
print("Closing.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment