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

3.2k views Asked by At

First of all, I know, there were people having the same problem BUT their fixes does not work for me.

So the exception that I get is:

java.net.BindException: bind failed: EACCES (Permission denied) on line "serverSocket = new ServerSocket(port);" and i cant figure out where the problem is. I tryed:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

Checking for premission:

if (ContextCompat.checkSelfPermission(this, Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED) {
It returned permisson granted

and the last thing that i tryed was using different ports including below and above 1024.

please help

EDIT: I just had Facepalm moment, i created dialog where i type port in BUT i forgot to pass the value so all that time it tryed to connect over port 1000 (that is unavalible in linux and unix systems), so anyways, thanks for stoping by over this thread and im sorry for wasting any of you guys time

1

There are 1 answers

0
Mans On BEST ANSWER

I think you don't really need to check that the INTERNET permission is granted or not. It's always granted if you defined it in MANIFEST. Maybe you are facing a error in testing: Just try uninstalling and installing your app again. I recently wrote a piece of code which runs a TCP server without experiencing that problem.