gpt4 book ai didi

android - OpenFire 服务器检查 XMPP 的连接

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:30:58 27 4
gpt4 key购买 nike

我在我的应用程序中使用明火,但我无法检查我的用户是否已连接到服务器,请告诉我如何检查。

最佳答案

检查这个给定的方法

 public XMPPConnection connect(final String username, final String password,
final String host, final String service, final String port) {
// Create a connection
ConnectionConfiguration connConfig = new ConnectionConfiguration(host, Integer.parseInt(port), service);
connConfig.setSASLAuthenticationEnabled(false);


try {
connection = new XMPPConnection(connConfig);
connection.connect();
Log.i("XMPPClient",
"[SettingsDialog] Connected to " + connection.getHost());
} catch (XMPPException ex) {
Log.e("XMPPClient", "[SettingsDialog] Failed to connect to "
+ connection.getHost());
Log.e("XMPPClient", ex.toString());
}

//Login to the server
try {
connection.login(username, password, "Smack" + new Date().getTime());
Log.i("XMPPClient", "Logged in as " + connection.getUser());
Presence presence = new Presence(Presence.Type.available);// Set the presence to available
connection.sendPacket(presence);
} catch (XMPPException ex) {
Log.e("XMPPClient", "[SettingsDialog] Failed to log in as " + username);
Log.e("XMPPClient", ex.toString());
return null;
}
//initialize();


initialize();//Add packet listener on connection for listen any message received

return connection;
}

此连接对象将帮助您确定您的用户是否已连接

关于android - OpenFire 服务器检查 XMPP 的连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34738160/

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