android基于openfire+spark+amack 即时聊天--------<2>登录遇到的问题和重要类解析
2015-03-21 16:33
483 查看
android基于openfire+spark+amack 即时聊天--------<2>登录遇到的问题和重要类解析
1.登录
1.1 public class ConnectionConfiguration
extends java.lang.Object implements java.lang.Cloneable
描述:
Configuration to use while establishing the connection to the server. It is possible to configure the path to the trustore file that keeps the trusted CA root certificates and enable or disable all or some of the checkings done while verifying server certificates.
It is also possible to configure if TLS, SASL, and compression are used or not.
意思大体是这样: 当与服务器建立连接的时候配置使用。它也能配置代理文件(能使受信任的CA根证书和启用或禁用的部分或全部的服务器检查证书的完成)
还可以配置如果TLS,SASL,和使用压缩或者不使用压缩。
1.2 使用的方法
setCompressionEnabled(boolean compressionEnabled)
是否使用流压缩,流压缩要求TLS建立后(是否启用了TLS),并且服务器提供流压缩,使用流压缩可以减少网络流量高达90%。默认情况下禁用压缩。
[code]public boolean isSASLAuthenticationEnabled();返回true时如果客户机将使用SASL验证登录到服务器。如果SASL授权失败,那么客户端将尝试使用non-sasl身份验证。默认情况下启用SASL。
[/code]
[code]public void setSASLAuthenticationEnabled(boolean saslAuthenticationEnabled)设置是否使用SASL验证,如果验证失败客户端将会使用无验证授权,默认是可以使用
[/code]
[code]public void setReconnectionAllowed(boolean isAllowed)设置是否允许重新连接机制,默认是允许[/code]
[code]setSecurityMode(ConnectionConfiguration.SecurityMode securityMode)设置TLS安全模式时使用的连接。默认情况下,模式是ConnectionConfiguration.SecurityMode.enabled。
[/code]
1.3
[code]public class XMPPConnectionextends Connection
创建一个套接字连接到XMPP服务器。这是默认连接Jabber服务器并在XMPP中指定核心2.登录关键代码:
package com.example.chatdemo; import org.jivesoftware.smack.ConnectionConfiguration; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.packet.Presence; import org.jivesoftware.smackx.pubsub.PresenceState; import android.content.Context; public class ClientConServer { private Context context; private static int PORT = 5222; private String host = "10.2.9.1"; public ClientConServer(Context context) { this.context = context; } public String login(String username, String pass) { ConnectionConfiguration configuration = new ConnectionConfiguration( host, PORT); // 是否允许重新连接 configuration.setReconnectionAllowed(true); // 是否允许使用压缩 configuration.setCompressionEnabled(false); // 设置TLS安全模式时使用的连接 configuration .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled); // 是否使用SASL configuration.setSASLAuthenticationEnabled(false); XMPPConnection xmppConnection = new XMPPConnection(configuration); try { XMPPConnection.DEBUG_ENABLED = true; xmppConnection.connect(); xmppConnection.login(username, pass); //代表XMPP存在数据包 常量值在api中查看吧 Presence presence = new Presence(Presence.Type.available); presence.setStatus("Q我吧"); xmppConnection.sendPacket(presence); return "success"; } catch (XMPPException e) { // TODO Auto-generated catch block e.printStackTrace(); return e.getMessage(); } } }
3.遇到的问题
注意端口号的正确(502),是否设置授权(401) 我在写的时候就遇到了相关文章推荐
- openfire+spark+amack 即时聊天--------<1>背景知识
- android定位已获取经纬度,上传google解析后textview不显示,基础问题,求大神解答~~>_<`
- <2>Android HAL 发展。文件。两种架构。实例解析
- PHP无法解析短标签<? ?>的解决方案——不是引号的问题哦
- IM 开源项目 登录服务器 基础表结构<2>
- 【Tomcat】Myeclipse+tomcat遇到的问题(Address already in use: JVM_Bind<null>:8080)
- Android 学习意外第五季<2>——google GPS定位由经纬度转换地址信息
- android SDK问题:<dl-ssl.google.com> != <www.google.com>
- Android基于XMPP Smack Openfire下学习开发IM(一)实现用户注册、登录、修改密码和注销等
- android之List<T>的空指针问题_List的初始化
- Android基于XMPP Smack openfire 开发的聊天室(二) 【聊天信息、成员】
- Android基于XMPP Smack Openfire开发IM(2)登录openfire
- Android基于XMPP Smack openfire 开发的聊天室(二) 【聊天信息、成员】
- 解决用虚拟机或者公司网络下载android源码,遇到DownloadError: android.googlesource.com: <urlopen error [Errno 110] Connection timed out>的问题
- Android基于XMPP Smack Openfire下学习开发IM(四)单人聊天和多人聊天(发送消息、接收消息)
- android-->图像旋转遇到的问题
- android 4.0 编译模式 eng - > user 时遇到的有关问题
- <开源>基于Android的点对点视频通信/RTSP/RTP/H.264
- Android基于XMPP Smack Openfire下学习开发IM(四)单人聊天和多人聊天(发送消息、接收消息)
- 基于avd7181c解决视频输入效果差的问题<四>---android显示相关实现调试手记