gpt4 book ai didi

android - 如何使用 smack-android 连接到安全禁用的 ejabberd?

转载 作者:行者123 更新时间:2023-11-29 20:53:47 25 4
gpt4 key购买 nike

我在使用 smack 4.1.0-beta2 连接到我的 ejabberd 2.1.11 服务器时遇到问题。我认为它与 SSL 证书有关并且不想处理那些我只是在运行 ejabberd 而不启动 TLS 的东西。我知道这是有效的,因为我能够使用 psi 连接到 ejabberd,而不会警告我一些自签名证书。

无论如何,我正在使用以下 ConnectionConfiguration 的

XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();
configBuilder.setUsernameAndPassword("username", "password");
configBuilder.setServiceName("myapp.ddns.net");
configBuilder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
configBuilder.setCompressionEnabled(false);
AbstractXMPPConnection xmppConnection = new XMPPTCPConnection(configBuilder.build());

所以当我尝试 xmppConnection.connect() 时,我得到以下异常

02-05 01:01:42.965  17047-17047/net.ddns.myapp W/DNSUtil﹕ Exception while resovling SRV records for myapp.ddns.net. Consider adding '_xmpp-(server|client)._tcp' DNS SRV Records
android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:175)
at libcore.io.IoBridge.sendto(IoBridge.java:463)
at java.net.PlainDatagramSocketImpl.send(PlainDatagramSocketImpl.java:182)
at java.net.DatagramSocket.send(DatagramSocket.java:287)
at de.measite.minidns.Client.query(Client.java:199)
at de.measite.minidns.Client.query(Client.java:174)
at de.measite.minidns.Client.query(Client.java:236)
at de.measite.minidns.Client.query(Client.java:149)
at org.jivesoftware.smack.util.dns.minidns.MiniDnsResolver.lookupSRVRecords(MiniDnsResolver.java:79)
at org.jivesoftware.smack.util.DNSUtil.resolveDomain(DNSUtil.java:162)
at org.jivesoftware.smack.util.DNSUtil.resolveXMPPDomain(DNSUtil.java:119)
at org.jivesoftware.smack.AbstractXMPPConnection.populateHostAddresses(AbstractXMPPConnection.java:551)
at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectUsingConfiguration(XMPPTCPConnection.java:506)
at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal(XMPPTCPConnection.java:810)
at org.jivesoftware.smack.AbstractXMPPConnection.connect(AbstractXMPPConnection.java:355)
at net.ddns.myapp.MainActivity.onCreate(MainActivity.java:61)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993)
at android.app.ActivityThread.access$600(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4507)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)

还有

02-05 01:01:42.980  17047-17047/net.ddns.myapp E/MyApp﹕ Error while establishing XMPPConnection
org.jivesoftware.smack.SmackException$ConnectionException: The following addresses failed: myapp.ddns.net:5222 Exception: null
at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectUsingConfiguration(XMPPTCPConnection.java:551)
at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal(XMPPTCPConnection.java:810)
at org.jivesoftware.smack.AbstractXMPPConnection.connect(AbstractXMPPConnection.java:355)
at net.ddns.myapp.MainActivity.onCreate(MainActivity.java:61)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993)
at android.app.ActivityThread.access$600(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4507)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)

最佳答案

对于android.os.NetworkOnMainThreadException,你需要

if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);}

也可以尝试设置主机值

   configBuilder.setHost("myapp.ddns.net");

关于android - 如何使用 smack-android 连接到安全禁用的 ejabberd?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28335688/

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