Selector.open() uses two TCP ports on Windows
843790May 22 2008 — edited May 22 2008As part of a security review, we are monitoring the ports opened by our application (which uses NIO) using TCPView on Windows Vista Business with sp1.
I ran the NIO test below.
public class NioSelectorMain {
public static void main(String[] args) throws Exception {
Selector selector = Selector.open();
System.out.println(selector);
Thread.sleep(Integer.MAX_VALUE);
}
}
Example output is:
sun.nio.ch.WindowsSelectorImpl@b1c5fa
TCPView showed the following two ports opened - the numbers change each time obviously, but there are always two ports.
javaw.exe:8224 TCP aled-PC:50741 localhost:50742 ESTABLISHED
javaw.exe:8224 TCP aled-PC:50742 localhost:50741 ESTABLISHED
I've tried this with sun jdk1.6.0_05 and jdk1.5.0_14. When running the same test on Linux, no ports are opened.
Why are these ports used, and is there any way to either prevent them from being opened or to specify which ports should be used?
Thanks in advance, Aled