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();
2
  • 5
    You do have network permissions in your manifest, right? Commented Nov 2, 2010 at 3:55
  • 2
    and also, regarding to such Exceptions, read the details in the LogCat screen and Console gives a lot of help. Commented Nov 2, 2010 at 3:58

2 Answers 2

87

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

<uses-permission android:name="android.permission.INTERNET" />
Sign up to request clarification or add additional context in comments.

1 Comment

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: stackoverflow.com/questions/38284554/…
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.

Comments

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.