There is no way to know before you actual bound it as the system may re-use it in the meantime.
> On 1. Dec 2020, at 15:41, Tim Fox <[email protected]> wrote: > > Hi folks, > > When using Netty I know I can specify local port as zero before binding and > then after the bindfuture has completed I can read the actual port. > > However, I need to know the ephemeral port before the server socket is bound > and the system is ready to accept connections. > > I can get my own ephemeral port manually before binding by opening a > ServerSocket like this: > > ServerSocket s = new ServerSocket(0); > int localPort = s.getLocalPort(); > > However I have to close that port before I can pass the result to Netty to > bind the actual socket, but that means there's a race condition where > something else can get the port assigned between it being closed and Netty > creating its ServerSocket. > > Any thoughts on how I can resolve this? > > > > -- > You received this message because you are subscribed to the Google Groups > "Netty discussions" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] > <mailto:[email protected]>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/netty/75f8769b-11c6-47b0-9028-1cf38580e68bn%40googlegroups.com > > <https://groups.google.com/d/msgid/netty/75f8769b-11c6-47b0-9028-1cf38580e68bn%40googlegroups.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "Netty discussions" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/netty/D28E373C-1723-4CBB-8451-AB238A7466E5%40googlemail.com.
