gpt4 book ai didi

java - 请求 INTERNET 权限的 BindException

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:20:36 25 4
gpt4 key购买 nike

我在使用 Android 时看到了几个关于 SocketException 的问题,但没有一个问题涉及我在 list 中指定的 INTERNET 权限下得到的 BindException。

这是我的 list 的一部分:




    
<使用权限 android:name="android.permission.ACCESS_NETWORK_STATE">
<使用权限 android:name="android.permission.ACCESS_WIFI_STATE">





<使用权限 android:name="android.permission.AUTHENTICATE_ACCOUNTS">

这是我的 LogCat 输出的相关部分:

04-22 14:49:06.117: DEBUG/MyLibrary(4844): Address to bind: 192.168.1.14 port: 84304-22 14:49:06.197: WARN/System.err(4844): java.net.BindException: Permission denied (maybe missing INTERNET permission)04-22 14:49:06.207: WARN/System.err(4844):     at org.apache.harmony.luni.platform.OSNetworkSystem.socketBindImpl(Native Method)04-22 14:49:06.207: WARN/System.err(4844):     at org.apache.harmony.luni.platform.OSNetworkSystem.bind(OSNetworkSystem.java:107)04-22 14:49:06.217: WARN/System.err(4844):     at org.apache.harmony.luni.net.PlainSocketImpl.bind(PlainSocketImpl.java:184)04-22 14:49:06.217: WARN/System.err(4844):     at java.net.ServerSocket.bind(ServerSocket.java:414)04-22 14:49:06.227: WARN/System.err(4844):     at org.apache.harmony.nio.internal.ServerSocketChannelImpl$ServerSocketAdapter.bind(ServerSocketChannelImpl.java:213)04-22 14:49:06.227: WARN/System.err(4844):     at java.net.ServerSocket.bind(ServerSocket.java:367)04-22 14:49:06.237: WARN/System.err(4844):     at org.apache.harmony.nio.internal.ServerSocketChannelImpl$ServerSocketAdapter.bind(ServerSocketChannelImpl.java:283)04-22 14:49:06.237: WARN/System.err(4844):     at mylibrary.net.PolicyConnection$PolicyServerWorker.(PolicyConnection.java:201)

I Really hope this is a simple problem and not something complicated by the fact that the binding is occurring within a worker thread on a port less than 1024.

Update

Looks as if this is a privileged port issue, anyone know how to bind to ports lower than 1024 in Android?


SelectorProvider provider = SelectorProvider.provider();
try {
ServerSocketChannel channel = provider.openServerSocketChannel();
policySocket = channel.socket();
Log.d("MyLibrary", "Address to bind: " + device.getAddress().getAddress() + " port: 843");
InetSocketAddress addr = new InetSocketAddress(InetAddress.getByName(device.getAddress().getAddress()), 843);
policySocket.bind(addr);
policySocket.setReuseAddress(true);
policySocket.setReceiveBufferSize(256);
} catch (Exception e) {
e.printStackTrace();
}

最佳答案

anyone know how to bind to ports lower than 1024 in Android?

要么 root 手机,修改固件,要么不要绑定(bind)到低于 1024 的端口。这是 Linux 的事情,而不是 Android 的事情。

关于java - 请求 INTERNET 权限的 BindException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2694797/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com