You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I understand that in some TCP stacks, if you listen on port "0", a randomly-chosen and available port will be provided for you.
I would like to be able to use port=0 in ForwardedPortDynamic, to guarantee that an available port is chosen, and be able to use the actually bound port in later code. ForwardedPortDynamic does not update BoundHost or BoundPort after the socket starts listening.
usingvarsshClient=newSshClient(sshHost,sshPort,sshUser,sshPass);awaitsshClient.ConnectAsync(token);// I would like to do thisusingvarportForward=newForwardedPortDynamic(0);// my current solution to choose a random (and hopefully available) port// using var portForward = new ForwardedPortDynamic((uint)System.Random.Shared.Next(1024, 65535)); sshClient.AddForwardedPort(portForward);portForward.Start();// Use FluentFTP to connect to a remote server via the SOCKS proxy created by SSH.NETvarftpClient=newAsyncFtpClientSocks5Proxy(newFtpProxyProfile(){ProxyHost="127.0.0.1",ProxyPort=(int)portForward.BoundPort,// I need the port here, but it is still "0"FtpHost=ftpHost,FtpPort=(int)ftpPort,FtpCredentials=newNetworkCredential(ftpUser,ftpPass),});awaitftpClient.Connect()
...
Is there a way to bind a random port that is guaranteed to be available and re-use it later?
The text was updated successfully, but these errors were encountered:
I understand that in some TCP stacks, if you listen on port "0", a randomly-chosen and available port will be provided for you.
I would like to be able to use
port=0
in ForwardedPortDynamic, to guarantee that an available port is chosen, and be able to use the actually bound port in later code.ForwardedPortDynamic
does not updateBoundHost
orBoundPort
after the socket starts listening.Is there a way to bind a random port that is guaranteed to be available and re-use it later?
The text was updated successfully, but these errors were encountered: