我正在设计一个聊天应用程序,使用ejabberd作为XMPP服务器和Smack4.1API。下面是管理连接的代码片段。
// 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.");My Requirement:
我的问题是:
需要建议:
发布于 2015-06-10 09:09:30
虽然问题不同,但我回答的这是如此可能会有所帮助(评论也是如此),但简单地说:
打开和关闭每条消息的连接都是,而不是,您应该做什么。
关于保持连接空闲(如WhatsApp),它是其中一个选项(查看服务),另一个选项是在应用程序运行时连接并保持连接,并在应用程序未运行时使用推送通知。
另一种选择是两者的结合(更接近WhatApp的功能)。
希望这能有所帮助。
https://stackoverflow.com/questions/30188721
复制相似问题