pmilin wrote:
I think you miss understood the concept, like Darkoperator said ForwardedPortDynamic is like a SOCKS 5 Proxy, so you just specify one localport (eg. 8080) and every application that proxy aware (eg. web browser) use that port as proxy to connect to any host and let SSH net handle the data exchange.
In ForwardedPortLocal you have to specify one port for every single remote host you want to forward. For example you give localport 3306 to forward connection to somehost:3306, so localport 3306 is only connected to somehost:3306. If you want to connect to other host, just add more ForwardedPortLocal in your application.
Regards
Thanks. I have since figured out that I will need to find the first available port and pass that to the ForwardedPortLocal constructor.Hi,
I was looking at the code for the local port forward and see that a TCPListener is being used with the address and port that is passed in. To my knowledge, if the TCPListener is given port 0, it will find the first available. This is the method I use to find the first available port. The trouble is that trying to find the first availabale port outside of the port forward class results in a race condition (the port could be taken in the time between when it is discovered as free and when the port forward class creates the listener).
I was thinking it would be nice to have the BoundPort property on the ForwardedPortLocal class be used to get the port from the IPEndPoint that is created when Start() is called on the ForwardedPortClass. I can then use the resulting port when creating a socket connection, which is what I am doing.
The code for getting the port from the listener is simply: BoundPort = ((IPEndPoint) listener.LocalEndpoint).Port
In cases where the port passed in is not zero, then the endpoint port should be the same as what was passed in. If the port passed in is zero, then BoundPort will return the actual port that is being used.
To go a step further, a new constructor could be created that doesn't take a port parameter at all. In this case zero would be the default.
Anybody have any thoughts about this.
I think you miss understood the concept, like Darkoperator said ForwardedPortDynamic is like a SOCKS 5 Proxy, so you just specify one localport (eg. 8080) and every application that proxy aware (eg. web browser) use that port as proxy to connect to any host and let SSH net handle the data exchange.
In ForwardedPortLocal you have to specify one port for every single remote host you want to forward. For example you give localport 3306 to forward connection to somehost:3306, so localport 3306 is only connected to somehost:3306. If you want to connect to other host, just add more ForwardedPortLocal in your application.
Regards