简单的 smack jabber 程序需要很长时间才能连接 android
simple smack jabber program taking very long to connect on android
使用smack jabber library 4.3.1, my android program takes 84 seconds to connect, which is fairly long. I have seen a discussion in a forum解决类似问题,但它影响了早期版本的 SMACK。
我做错了什么?
下面是用于连接的代码。
XMPPTCPConnectionConfiguration cc= XMPPTCPConnectionConfiguration.builder()
.setCompressionEnabled(true)
.setUsernameAndPassword("smackuser","ilovesmack")
.setXmppDomain("xmpp.jp")
.setSecurityMode(ConnectionConfiguration.SecurityMode.required)
.build();
connection=new XMPPTCPConnection(cc);
connection.addConnectionListener(MainActivity.this);
connection.connect();
connection.login();
只需调用一次。例如在应用程序 class
AndroidSmackInitializer.initialize(Context);
在任何 XMPP 连接之前
[旧答案。不要使用]
我发现了问题。 SMACK jabber 使用 minidns and minidns has a recently fixed bug on android 8。我使用下面的代码解决了这个问题。感谢@Flow
//////////////////////smack///////////////////////////////////////
implementation "org.igniterealtime.smack:smack-android-extensions:4.3.1"
implementation "org.igniterealtime.smack:smack-experimental:4.3.1"
implementation "org.igniterealtime.smack:smack-tcp:4.3.1"
implementation 'de.measite.minidns:minidns-hla:0.2.4'//added this
添加了 minidns 依赖项
import org.minidns.dnsserverlookup.android21.AndroidUsingLinkProperties;
AndroidUsingLinkProperties.setup(context);//add this
cc=XMPPTCPConnectionConfiguration.builder()
.setCompressionEnabled(true)
.setUsernameAndPassword(username,password)
.setXmppDomain(domain)
.build();
xmpptcpConnection=new XMPPTCPConnection(cc);
xmpptcpConnection.addConnectionListener(this);
xmpptcpConnection.connect();
xmpptcpConnection.login();
使用smack jabber library 4.3.1, my android program takes 84 seconds to connect, which is fairly long. I have seen a discussion in a forum解决类似问题,但它影响了早期版本的 SMACK。
我做错了什么?
下面是用于连接的代码。
XMPPTCPConnectionConfiguration cc= XMPPTCPConnectionConfiguration.builder()
.setCompressionEnabled(true)
.setUsernameAndPassword("smackuser","ilovesmack")
.setXmppDomain("xmpp.jp")
.setSecurityMode(ConnectionConfiguration.SecurityMode.required)
.build();
connection=new XMPPTCPConnection(cc);
connection.addConnectionListener(MainActivity.this);
connection.connect();
connection.login();
只需调用一次。例如在应用程序 class
AndroidSmackInitializer.initialize(Context);
在任何 XMPP 连接之前
[旧答案。不要使用]
我发现了问题。 SMACK jabber 使用 minidns and minidns has a recently fixed bug on android 8。我使用下面的代码解决了这个问题。感谢@Flow
//////////////////////smack///////////////////////////////////////
implementation "org.igniterealtime.smack:smack-android-extensions:4.3.1"
implementation "org.igniterealtime.smack:smack-experimental:4.3.1"
implementation "org.igniterealtime.smack:smack-tcp:4.3.1"
implementation 'de.measite.minidns:minidns-hla:0.2.4'//added this
添加了 minidns 依赖项
import org.minidns.dnsserverlookup.android21.AndroidUsingLinkProperties;
AndroidUsingLinkProperties.setup(context);//add this
cc=XMPPTCPConnectionConfiguration.builder()
.setCompressionEnabled(true)
.setUsernameAndPassword(username,password)
.setXmppDomain(domain)
.build();
xmpptcpConnection=new XMPPTCPConnection(cc);
xmpptcpConnection.addConnectionListener(this);
xmpptcpConnection.connect();
xmpptcpConnection.login();