I'm wondering if/how I can realize the following setup. It doesn't seem to fit the standard ssh port forwarding model.
I have a client machine A. I have a server application running on machine A, which listens on port X. However, machine A is behind a common IP-address (shared by many users) so it can't receive incoming connections to port X from the internet. However, I have access to a machine, B, in Amazon EC2 and it would be OK connections would go through that machine. It's not possible to move the application to this machine in EC2.
Hence, what I want, is to have machine B listen on port X and forward all connections/communications to machine A. Machine A has to see it as if clients are connecting to port X in the usual way (it would be acceptable that the source IP appears as machine B).
The solution must work in such a way that machine A is the client that connects to machine B. So in the case of ssh, A would have to be the ssh client and B the ssh server. Again, this is because machine A is behind the common IP, hence all connections have to be outgoing from A.
How can this setup be realized? Preferably using commonly available and free software? Thank you in advance.