Java 套接字 IOException - 权限被拒绝

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4074808/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 11:18:56  来源:igfitidea点击:

Java socket IOException - permission denied

javaandroidsocketspermissions

提问by Grant

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.

我正在尝试使用以下 java 代码连接到我的网络上运行 tcp 侦听器的服务器。我收到 IOException - 权限被拒绝。它来自 android 2.2 模拟器。

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();

采纳答案by dongshengcn

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

是的,就像上面的莫里森所说,您可能需要将此权限放入清单文件。

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

回答by Pir Fahim Shah

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

可能有两个原因,要么你没有把这行代码放在 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.

或者可能是由于防火墙设置。您的日食可能已被防火墙阻止通过网络进行通信。