Search code examples
windows-firewall

Firewall Not asking Permission to open the port


I am writing the following java program for opening a port in Windows. As of my knowledge whenever we are opening a port, Firewall should ask for the permission to allow the access. But here without intimation it is opening. What is the reason behind it.

MyCode

import java.net.*;
import java.io.*;

class Server
{
    public static void main(String[] args) throws Exception
    {
        if(args.length!=1)
        {
            System.out.println("Enter the Port Number");
            return;
        }
        int portNumber = Integer.parseInt(args[0]);
        ServerSocket ss = new ServerSocket(portNumber);
        while(true)
        {
            Socket socket = ss.accept();
            ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
            String message = (String)ois.readObject();
            System.out.println("Client: "+message);
            if(message.equals("exit")) break;
            ois.close();
        }
        ss.close();
    }
}

Solution

  • The Windows Firewall will prompt the user to "allow an application" whenever it sees a program open a listening socket port that doesn't have a rule associated with it. (i.e. new programs). But when the user clicks "allow" on the confirmation dialog, it's for the entire program, not just one port. And it typically does not prompt the user again once confirmation is given.

    In the case of Java, the running program is Java.exe. So once the user clicks "allow" to the first program running Java, all subsequent Java programs get enabled without prompting. I would also suspect that the Java installer just sets a Firewall rule for itself as well. I seem to have several:

    In other words, you already got Java registered, so you aren't getting prompted again.