Allow specific connection windows firewall

19 Views Asked by At

So I have this code on my pc java app:

try {
            ServerSocket serverSocket = new ServerSocket(4444);

            while (true) {
                 Socket clientSocket = serverSocket.accept();
                new ClientHandler(clientSocket).start();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

and this code in my android studio app

public void sendCommand(String command) {
        new Thread() {
            @Override
            public void run() {
                try {
                    if (getEnableSwitch().isChecked()) {
                        // Log.d("TAG", getSettingByName("PC IP").getSValue());
                        Socket socket = new Socket();
                        socket.connect(new InetSocketAddress(getSettingByName("PC IP").getSValue(), 4444), 5000);
                        PrintWriter out = new PrintWriter(socket.getOutputStream(), true);

                        out.println(command + "|" + getSettingByName("Song url").getSValue());
                        out.close();
                        out.flush();
                        socket.close();
                    }
                } catch (IOException e) {
                    Log.i("TAG", e.getMessage());
                }
            }
        }.start();
    }

So I am trying to send commands from my phone to my pc but it only works when I disable my firewall, is there any way to accept the connection and prevent firewall from blocking the connection?

  • added inbound rule for port but didn't work
0

There are 0 best solutions below