0

I'm an android beginner. I want to create a ServerSocket, but it always calls "java.net.SocketException: Permission denied" back on line "serverSocket = new ServerSocket(12345);" I want to know why, thank you.

ServerThread.java

public class ServerThread extends Thread {
    ServerSocket serverSocket ;
    @Override
    public void run() {
        try {
            serverSocket = new ServerSocket(12345);
            while(true) {
                System.out.println("IN");
                Socket socket = serverSocket.accept(); // null
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

MainActivity.java

public class MainActivity extends AppCompatActivity {

   @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        new ServerThread().start();
    }
}
4
  • Does this answer your question? java.net.SocketException: Permission denied for android Commented Sep 17, 2020 at 9:31
  • 1
    I saw that before but I have already added the permission. And he didn't use socket, so I ask here, thank you. Commented Sep 17, 2020 at 9:42
  • no problem, i thought it was a duplicate because I didn't see your manifest Commented Sep 17, 2020 at 9:44
  • check if the port is not blocked by the firewall Commented Sep 17, 2020 at 10:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.