【发布时间】:2015-07-23 04:48:05
【问题描述】:
我正在设计一个使用 ejabberd 作为 XMPP 服务器和 Smack 4.1 API 的聊天应用程序。下面是管理连接的代码sn-p。
// Create a connection to the server.com server on 5222 port.
XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
.setUsernameAndPassword("user", "password")
.setServiceName("server.com")
.setHost("server.com_ip")
.setPort(5222)
.setSecurityMode(SecurityMode.disabled)
.build();
XMPPTCPConnection conn = new XMPPTCPConnection(config);
try {
conn.connect();
System.out.println("Connection established.");
conn.login();
System.out.println("Logged in.");
} catch (SmackException | IOException | XMPPException e) {
System.out.println("Connection not established: " + e.getMessage());
}
聊天和 muc 的一些处理。
// Disconnect
conn.disconnect();
System.out.println("Connection Closed.");
我的要求:
- 一旦用户登录应用程序,他们可能会连续几个月都不会退出。与 Whatsapp 的工作方式完全相同。
我的问题是:
- 只要用户登录就保持连接打开是个好主意吗?
- 如果不是,那么为每条聊天消息打开和关闭连接是否是个好主意?
需要建议:
- 处理与 XMPP 服务器的连接最有效的方法是什么?
【问题讨论】:
-
我自己也有类似的问题。我正在使用 openfire xmpp 服务器制作一个原型即时消息应用程序。来自一个一无所知的地方,我说处理连接的最佳方法是在一段时间后关闭连接(如果不使用)。
-
兄弟你的问题有什么更新吗?实际上我面临着与 xmpp @vinod 建立连接相关的问题
-
1.使用 Android 服务始终保持连接活动,或者 2. 如果应用程序打开,则保持连接活动,如果应用程序关闭,则使用推送通知。
标签: xmpp xmppframework