How come when I try listening to a loopback host in Java (using a plain old socket), it requires root access, yet if I use nio, it doesn't? If I tried listening on any other language on the loopback, it doesn't require any elevated privileges too.
This is my code right now:
import java.net.*;
class Test
{
public static void main( String[] args )
throws Exception
{
ServerSocket server = new ServerSocket( 80 );
while( true )
{
Socket socket = server.accept();
System.out.print( "." );
}
}
}
When I run this as a normal user, this exception is thrown: Exception in thread "main" java.net.BindException: Permission denied
. Yet when I run this as root, it works fine as expected.