android - 测试 aws-sdk-android-samples/AndroidPubSub 但连接被拒绝
问题描述
我试图从中进行测试aws-sdk-android-samples/AndroidPubSub/
,https://github.com/awslabs/aws-sdk-android-samples/tree/master/AndroidPubSub
但是在单击连接后,总是会收到错误消息
30000 毫秒后 a2k94wsqkar4rm-ats.iot.us-west-2.amazonaws.com/52.13.183.162(端口 8883):isConnected 失败:ECONNREFUSED(连接被拒绝)
我在 AWS IoT 控制台上创建了我的设备证书并将其激活,并附加了如下所述的策略,
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "iot:Connect",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"iot:Publish",
"iot:Subscribe",
"iot:Receive"
],
"Resource": "*"
}
]
}
我尝试了两种方法将证书和密钥安装到本地密钥库,并且它们都有效。
方法一,通过源码
AssetManager assetManager = getAssets();
// read cert and private key from pem file
InputStream input = assetManager.open("4ed2c76117-private.pem");
int size = input.available();
byte[] buffer = new byte[size];
input.read(buffer);
input.close();
String privateKeyPem = new String(buffer);
System.out.println(privateKeyPem);
input = assetManager.open("4ed2c76117-certificate.pem");
size = input.available();
byte[] buffer2 = new byte[size];
input.read(buffer2);
input.close();
String certPem = new String(buffer2);
System.out.println(certPem);
// store in keystore for use in MQTT client
// saved as alias "default" so a new certificate isn't
// generated each run of this application
AWSIotKeystoreHelper.saveCertificateAndPrivateKey(certificateId,
certPem,
privateKeyPem,
keystorePath, keystoreName, keystorePassword);
// load keystore from file into memory to pass on
// connection
clientKeyStore = AWSIotKeystoreHelper.getIotKeystore(certificateId,
keystorePath, keystoreName, keystorePassword);
方法2,通过终端命令,
openssl pkcs12 -export -out iot_keystore.p12 -inkey 4ed2c76117-private.pem -in 4ed2c76117-certificate.pem -name default
keytool -importkeystore -srckeystore iot_keystore.p12 -srcstoretype pkcs12 -destkeystore iot_keystore.bks -deststoretype bks --provider org.bouncycastle.jce.provider.BouncyCastleProvider -–providerpath bcprov-jdk15on-164.jar
adb push iot_keystore.bks /data/user/0/com.amazonaws.demo.androidpubsub/files/iot_keystore
任何人都可以帮助解决这个问题吗?
解决方案
对不起,我认为这是一个模拟器网络问题。正确连接网络后,这个问题就消失了。
推荐阅读
- php - 在 ACF DateTimePicker 字段的 48 小时之前显示 DIV,并在相同 ACF DateTimePicker 字段的 24 小时之后隐藏
- crystal-reports - 需要以编程方式在水晶报表中上下移动部分
- extjs - 使 ExtJS 应用程序严格 CSP 兼容的技巧或覆盖
- r - 如何从 MLeval 获取测试数据 ROC 图
- android - 以编程方式生成自定义视图时不调用 onRestoreInstanceState
- postgresql - 我的项目没有连接到我的 Postgres 服务器
- python - 无法在 FoxDot 上播放声音
- python-3.x - 如何可靠地引用一个过程(使用标签或类似的东西)?
- javascript - 如何在其他路线中的其他组件中获取更新的道具?
- c - 请告诉我这段代码有什么问题