44

i am trying to connect to a server on my network running a tcp listener using the following java code. I am getting am IOException - Permission Denied. It is from an android 2.2 emulator.

Does anyone know why?

Socket socket = new Socket("1.1.1.1", 1111);
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
out.println("test");
socket.close();
Grant
  • 11,138
  • 32
  • 94
  • 140

2 Answers2

87

Yea, like Morrison said above, you probably need to put this permission to your manifest file.

<uses-permission android:name="android.permission.INTERNET" />
dongshengcn
  • 6,434
  • 7
  • 35
  • 44
  • Please note that this is not the permission that would appear in the app settings of your phone, as it is not one of the dangerous permissions. This will remove the Permission denied exception though. Refer: https://stackoverflow.com/questions/38284554/android-6-23-no-permission-requested – shabby Jan 15 '19 at 07:05
6

There may be two reason either you have't put this line of code in android.manifest

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

or it may be due to the Firewall setting. It may be possible that your eclipse have been blocked by Firewall to communicate through network.

Pir Fahim Shah
  • 10,505
  • 1
  • 82
  • 81