It's a intermediary server intended to act in name of a client, and sometimes to do something useful with the data before it reaches the original target. Let's see a picture:
My idea was to produce a proxy using only the default python library, and to guide me during development I set the following:
The Forward class is the one responsible for establishing a connection between the proxy and the remote server(original target).
The inputlist stores all the avaiable sockets that will be managed by select.select, the first one to be appended is the server socket itself, each new connection to this socket will trigger the onaccept() method.
If the current socket inputready (returned by select) is not a new connection, it will be considered as incoming data(maybe from server, maybe from client), if the data lenght is 0 it's a close request, otherwise the packet should be forwarded to the correct endpoint.
This method creates a new connection with the original target (proxy -> remote server), and accepts the current client connection (client->proxy). Both sockets are stored in inputlist, to be then handled by mainloop. A "channel" dictionary is used to associate the endpoints(client<=>server).
This method is used to process and forward the data to the original destination ( client <- proxy -> server ).
Disables and removes the socket connection between the proxy and the original server and the one between the client and the proxy itself.