aSmack 使用
来源:互联网 发布:黑暗之魂3帕奇捏脸数据 编辑:程序博客网 时间:2024/05/29 02:43
Smack
https://github.com/igniterealtime/Smack
aSmack项目
https://github.com/Flowdalic/asmack
从4.1开始smack已经支持Android了,aSmack项目也不再维护了。
aSmack 0.8.x 和4.x的改变还是很多的,对比一下他们的写法就知道了。(服务端 为 Openfire 3.10.0~3.10.2 默认配置)
0.8.x连接服务器的配置
ConnectionConfiguration config = new ConnectionConfiguration(HOST, PORT);SASLAuthentication.supportSASLMechanism("PLAIN", 0);// 设置登录状态为离线,默认为trueconfig .setSendPresence(false);config .setSendPresence(true);// 断网重连,默认为trueconfig .setReconnectionAllowed(true);XMPPConnection connction = new XMPPConnection(config);connection.connect();
这样就能够正常登录了。
4.x的代码片段
// 认证模式:PLAIN 最简单的,也是危险的SASLAuthentication.supportSASLMechanism("PLAIN", 0);ConnectionConfiguration config = new ConnectionConfiguration(SERVER_HOST, SERVER_PORT);// 设置登录状态为在线config.setSendPresence(true);// 断线重连config.setReconnectionAllowed(true);// 安全连接:根据服务器设置是否启用安全连接// 4.x默认开启,设置为禁用,否则提示证书错误之类的,需要配置证书 config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);connection = new XMPPTCPConnection(config);
- 0.8x中直接
new
一个XmppConnection
,而4.xXmppConnection
已经是抽象类了,只能通过其子类XmppTCPConnection
来实现了。 - 在4.x中DNS-java被移除了,需要手动添加。
而且还需要初始化 Android环境,貌似是用于DNS解析的广播声明SmackAndroid.init(getApplicationContext());
使用过程中可能出现各种错误,google一般都是有答案的。
0 0
- aSmack 使用
- Android asmack使用介绍
- Android asmack使用介绍
- Android asmack使用介绍
- Android asmack使用介绍
- Android asmack使用介绍
- Android asmack使用介绍
- asmack
- Asmack长链接框架使用
- Android之asmack使用介绍
- android 使用asmack库进行文件收发
- 使用asmack创建room的问题
- Android端使用asmack实现IM
- Asmack 聊天框架 使用(一)
- Android 即时通讯开发——asmack jar包使用
- IM ASmack
- asmack杂记
- asmack相关
- 2 - Python数学函数、字符串、对象
- [函数] 一个函数指针的问题
- 第12章 线程控制
- 3 - 条件选择语句
- Tomcat(8005,8080,8009)端口占用问题常见原因及解决方法
- aSmack 使用
- 4 - 循环
- 写开发文档时如何生成目录结构
- 【排序算法】总结
- 5 - 函数
- Mac上配置adb环境变量
- 杜升初
- 多线程数据共享
- Linux上安装weblogic