If you want to route only tcp traffic, it's really simple using streams and sockets . You must listen on a different port for each server you want to reach. Either in Java or Python, you need to create a "socket" for each port that you want to listen to.
For each new connection, you create a new connection to the server and create two new threads to handle this connection, one stream will read everything from the client and send it to the server. Another will read everything from the server and send it to the client. When either end of the connection closes it, you close the other and terminate both threads.
source share