Firewall Not asking Permission to open the port

邮差的信 提交于 2019-12-13 08:31:22

问题


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();
    }
}

回答1:


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.



来源:https://stackoverflow.com/questions/40719342/firewall-not-asking-permission-to-open-the-port

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!