美文网首页
Android开发笔记3:XMPP

Android开发笔记3:XMPP

作者: 陈兴强 | 来源:发表于2020-03-17 06:57 被阅读0次

一 简介

全称:Extensible Messaging and Presence Protocol,一个开源形式组织产生的网络即时通信协议,用于进行网络通信。
四部分组成:

P(Protocol):协议
一组标准化的通信协议

P(Presence):存在
实体的状态,在线/离线/忙碌。

M(Messaging):信息收发
使用非常有效推送机制实时发送消息。

X(eXtensible):可扩张的
可以扩张,以适应应用的变化。

二 解决了什么问题

1.XMPP核心
在说解决什么问题之前,我们先来看一下它用到核心技术,这些核心技术我们会从宏观上去看,当我们选择一个协议肯定是为了解决问题,如果对技术的基础了解比较深,我们很容易就能够知道,是否可以在我们项目中采用这个协议。

2.适合的平台

3.为什么要使用它

三 Android 怎么使用,相关开源库

Android中我们可以引用第三方开源库
Smack:
XMPP服务器通信以执行实时通信(包括即时消息传递和群聊)的库
如何使用可以查看以下网址:
https://github.com/igniterealtime/Smack

组成:

使用流程:
第一步 连接服务器

 private XMPPTCPConnectionConfiguration mConfiguration;
          try {

                // Create a connection to the XMPP chat server on a specific port.
                mConfiguration = XMPPTCPConnectionConfiguration.builder()
                        //设置xmpp的用户名和密码
                        .setUsernameAndPassword(username, password)
                        //服务器地址
                        .setHost(host)
                        //是否开启安全模式
                        .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
                        .setXmppDomain(JidCreate.domainBareFrom(serviceName))
                        //服务器端口
                        .setPort(Integer.parseInt(port))
                        //开启调试模式
                        .setDebuggerEnabled(true)
                        .build();


                mConnection = new XMPPTCPConnection(mConfiguration);
                //连接
                mConnection.connect();
                //登录到服务器
                mConnection.login();

            } catch (SmackException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (XMPPException e) {
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

连接服务器主要是XMPPTCPConnectionConfiguration.builder() 配置和XMPPTCPConnection连接配置
XMPPTCPConnection主要使用两个构造方法:
XMPPTCPConnection(StringserverName)方法:
XMPPTCPConnection(ConnectionConfigurationcc):

第二步

四 架构

五 核心模块

六 关键知识点

七 用到的数据结构

八 相关算法

九 用到的设计模式

十总结

相关文章

网友评论

      本文标题:Android开发笔记3:XMPP

      本文链接:https://www.haomeiwen.com/subject/zmeyshtx.html