receive_first true elsereceive_first false now spin up our listening socket server_loop(local_host,local_port,remote_host,remote_port,receive_firstmain(most of this should look familiarwe take in some command-line arguments and then fire up server loop that listens for connections when fresh connection request comes inwe hand it off to our proxy_handlerwhich does all of the sending and receiving of juicy bits to either side of the data stream let' dive into the proxy_handler function now by adding the following code above our main function def proxy_handler(client_socketremote_hostremote_portreceive_first)connect to the remote host remote_socket socket socket(socket af_inetsocket sock_streamremote_socket connect((remote_host,remote_port)receive data from the remote end if necessary if receive_firstremote_buffer receive_from(remote_sockethexdump(remote_buffersend it to our response handler remote_buffer response_handler(remote_bufferif we have data to send to our local clientsend it if len(remote_buffer)print "[<==sending % bytes to localhost len(remote_bufferclient_socket send(remote_buffernow lets loop and read from localsend to remotesend to local rinsewashrepeat while trueread from local host local_buffer receive_from(client_socketif len(local_buffer)print "[==>received % bytes from localhost len(local_ bufferhexdump(local_buffersend it to our request handler local_buffer request_handler(local_buffersend off the data to the remote host remote_socket send(local_bufferprint "[==>sent to remote receive back the response remote_buffer receive_from(remote_socketif len(remote_buffer)