我正在尝试使用sslContext.getServerSocketFactory((.createServerSocket(端口(创建服务器套接字;
但它拒绝给予例外许可。下面是我的完整代码。
private SSLServerSocket getSslServerSocket(int port)
throws GeneralSecurityException {
KeyManager[] keyManager = this.mKeyStoreManager.getKeyManagers();
TrustManager[] trustManager = this.mKeyStoreManager.getTrustManagers();
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManager, trustManager, (SecureRandom) null);
SSLServerSocket sslServerSocket = null;
try {
sslServerSocket = (SSLServerSocket) sslContext
.getServerSocketFactory().createServerSocket(port);
sslServerSocket.setNeedClientAuth(true);
sslServerSocket.setUseClientMode(false);
} catch (Exception ex) {
Log.e("----Exception", ex.getMessage());
}
return sslServerSocket;
}
我尝试了多个端口,但在所有端口上都出现了相同的错误。
以下是异常消息。java.net.SocketException:套接字失败:EACCES(权限被拒绝(
我知道这个问题很老了,但如果其他人正在寻找解决方案:添加
<uses-permission android:name="android.permission.INTERNET"/>
在AndroidManifest.xml中应该修复问题