我正在尝试使用 sslContext.getServerSocketFactory().createServerSocket(port); 创建服务器套接字
但其给予例外许可被拒绝。下面是我的完整代码。
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(权限被拒绝)