Created
September 13, 2011 23:27
-
-
Save Motoma/1215469 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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