Skip to content

Instantly share code, notes, and snippets.

@hgdeoro
Created August 20, 2011 15:46
Show Gist options
  • Save hgdeoro/1159255 to your computer and use it in GitHub Desktop.
Save hgdeoro/1159255 to your computer and use it in GitHub Desktop.
TCP forwarder to Apache on localhost
import eventlet
def closed_callback():
print "called back"
def forward(source, dest, cb = lambda: None):
while True:
d = source.recv(8096)
if d == '':
cb()
break
dest.sendall(d)
listener = eventlet.listen(('localhost', 7080))
while True:
client, addr = listener.accept()
server = eventlet.connect(('localhost', 80))
eventlet.spawn_n(forward, client, server, closed_callback)
eventlet.spawn_n(forward, server, client)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment