-1

I am trying to open port 25 on Android but for some reason I keep getting the following error

java.net.BindException: bind failed: EACCES (Permission denied)

Below is the code that I am using

ServerSocket ss = new ServerSocket(smtpPort);
                    Log.d("SMTPSocketHandler", "Socket created");
                    while (!end)
                    {
                        Socket s = ss.accept();
                        Log.d("SMTPSocketHandler", "Client Accepted");
                        BufferedReader input = new BufferedReader(new InputStreamReader(s.getInputStream()));
                        PrintWriter output = new PrintWriter(s.getOutputStream());

                        String stringData = input.readLine();
                        output.println("FROM Server - " + stringData.toUpperCase());
                        output.flush();
                        end = true;
                        output.close();
                        s.close();
                        break;
                    }
                    ss.close();

If I use another port though such as 5555 it then works. Is there a particular reason this isn't supported or is there something I can do to make it work?

Boardy
  • 35,417
  • 104
  • 256
  • 447

1 Answers1

2

As was mentioned in a comment, ports below 1024 require superuser/root permissions. This is not unique to Android — this is standard Unix/Linux behavior, and has been that way for a couple of decades.

See:

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491