<s> """<STR_LIT>""" <EOL> import sys <EOL> from twisted . internet import reactor <EOL> from eventlet . twistedutil import join_reactor <EOL> from eventlet . twistedutil . protocol import GreenClientCreator , SpawnFactory , UnbufferedTransport <EOL> from eventlet import proc <EOL> def forward ( source , dest ) : <EOL> try : <EOL> while True : <EOL> x = source . recv ( ) <EOL> if not x : <EOL> break <EOL> print '<STR_LIT>' % len ( x ) <EOL> dest . write ( x ) <EOL> finally : <EOL> dest . loseConnection ( ) <EOL> def handler ( local ) : <EOL> client = str ( local . getHost ( ) ) <EOL> print '<STR_LIT>' % client <EOL> remote = GreenClientCreator ( reactor , UnbufferedTransport ) . connectTCP ( remote_host , remote_port ) <EOL> a = proc . spawn ( forward , remote , local ) <EOL> b = proc . spawn ( forward , local , remote ) <EOL> proc . waitall ( [ a , b ] , trap_errors = True ) <EOL> print '<STR_LIT>' % client <EOL> try : <EOL> local_port , remote_host , remote_port = sys . argv [ <NUM_LIT:1> : ] <EOL> except ValueError : <EOL> sys . exit ( __doc__ ) <EOL> local_port = int ( local_port ) <EOL> remote_port = int ( remote_port ) <EOL> reactor . listenTCP ( local_port , SpawnFactory ( handler ) ) <EOL> reactor . run ( ) </s>
