问题描述
我一直在将smack 3.4用于我的Web门户.我的Android应用程式也使用asmack 3.4(aSmack的开发在几年前就停止了,但是在那儿我使用了一些非官方的jar.与此相关的是文件上传和群组聊天的问题,因此它希望升级到正式的smack,因为它现在已经获得了仿生的原生支持.)
I have been using smack 3.4 for my web portal. Also used asmack 3.4 for my android app(aSmack development stopped some years back but there where some unofficial jars that i used. Faced issues with file upload and group chat with this it so want to upgrade to official smack as it has andoid native support now).
但是现在有关于smack的更新,它们已经移至4.1(集成了android native):
But now there is a update on smack they have moved to 4.1(android native integrated):
https://github.com/igniterealtime/Smack/wiki/Smack-4.1-自述文件和升级指南.
因此,我正在寻找与 SMACK 4.1 alpha 和android/web集成在一起的代码示例/示例项目/代码段.请提供一些有用的链接.
So i am looking for some code example/sample project/code snippet with SMACK 4.1 alpha integrated with android/web.Please provide some helpful links.
有关执行/不执行此升级的建议.由于smack 4.1尚未发布.
Also advice on doing/or not doing this upgrade. As smack 4.1 is still not released.
谢谢.
推荐答案
使用SSL的连接示例(smack-4.1.0-beta2-SNAPSHOT-2015-02-01):
Example of connection using SSL (smack-4.1.0-beta2-SNAPSHOT-2015-02-01) :
XMPPTCPConnectionConfiguration.Builder config = XMPPTCPConnectionConfiguration.builder();
config.setSecurityMode(ConnectionConfiguration.SecurityMode.required);
//For OLD STYLE SSL
//config.setSecurityMode(ConnectionConfiguration.SecurityMode.enabled);
config.setUsernameAndPassword(USERNAME + "@" + DOMAIN, "PASSWORD");
config.setServiceName(DOMAIN);
config.setHost(DOMAIN);
config.setPort(PORT);
config.setDebuggerEnabled(true);
//OLD STYLE SSL
//config.setSocketFactory(SSLSocketFactory.getDefault());
try {
SSLContext sc = SSLContext.getInstance("TLS");
MemorizingTrustManager mtm = new MemorizingTrustManager(ctx);
sc.init(null, MemorizingTrustManager.getInstanceList(ctx), new SecureRandom());
config.setCustomSSLContext(sc);
config.setHostnameVerifier(mtm.wrapHostnameVerifier(new org.apache.http.conn.ssl.StrictHostnameVerifier()));
} catch (NoSuchAlgorithmException | KeyManagementException e) {
throw new IllegalStateException(e);
}
mConnection = new XMPPTCPConnection(config.build());
mConnection.setPacketReplyTimeout(10000);
try {
mConnection.connect();
mConnection.login();
} catch (SmackException | IOException | XMPPException e) {
e.printStackTrace();
}
- https://github.com/ge0rg/MemorizingTrustManager/tree/master/src /de/duenndns/ssl
- https://github.com/ge0rg/MemorizingTrustManager/tree/master/src/de/duenndns/ssl
聊天创建示例:
final ChatManager chatManager = ChatManager.getInstanceFor(mConnection);
chatManager.addChatListener(new ChatManagerListener() {
@Override
public void chatCreated(Chat chat, boolean b) {
chat.addMessageListener(new ChatMessageListener() {
@Override
public void processMessage(Chat chat, Message message) {
mServerResponse.gotMessage(message.getBody());
Log.d(TAG, message.toString());
}
});
}
});
Chat chat2 = chatManager.createChat(USERNAME + "@" + DOMAIN);
try {
chat2.sendMessage("text");
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
}
这篇关于smack 4.1 Openfire示例示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!