XMPP协议实现即时通讯底层书写(二)--IOSXMPPFrameworkDemo+分
我希望,This is a new day! 在看代码之前,我觉得你还是应该先整理一下心情,来听我说几句: 首先,我希望你是在早上边看这篇blog,然后一边开始动手操作,如果你只是看blog而不去自己对比项目,作用不是很大。一日之计在于晨,所以怀着一颗对技术渴望,激
我希望,This is a new day!
在看代码之前,我觉得你还是应该先整理一下心情,来听我说几句:
首先,我希望你是在早上边看这篇blog,然后一边开始动手操作,如果你只是看blog而不去自己对比项目,作用不是很大。一日之计在于晨,所以怀着一颗对技术渴望,激动的,亢奋的心情去学习,你才能有所得。嗯,就拿鄙人当时做项目来说,每天早上起来的第一件事情,就是研究XMPPFramework作者的代码,按照模块来分析和模仿书写,睡觉的时候还在思考,分析,总结...
当然我并不是说每个Dev 都要向我这样,只是希望你能保持一颗积极向上的心态去对待技术,对待你的工作。
that's all。
ResourceURL:https://github.com/robbiehanson/XMPPFramework (如果你还在维护你现有的基于XMPP的产品,那么你需要sometimes 去查看,原作者是否fix 一些bug)
IphoneXMPP Demo
1.AppDelegate.m
a.大概看下头文件,ok,别跳转深入看了,下面我会教快速的看。See this method
有几个地方需要注意:
1)DDLog 用于不用不强求,鄙人喜欢干净清爽的控制台,所以就没用这玩意,因为我并不是很依赖全部打log,而是断点控制台po XXX方法,实时性找出问题修复bug
2)配置XML Stream 流 ,给你的长连接里面增加各种 buff,各种装备,各种属性。ok,不开玩笑了:),这个配置很重要,它决定了你的app需要支持哪些xmpp服务,决定了原作者(罗宾逊)哪些代码功能模块是不需要生效的
3)启动连接,当然对应的也有一个cancel connect
b 设置你的 XML Stream ,开启哪些功能
- (void)setupStream { NSAssert(xmppStream == nil, @"Method setupStream invoked multiple times"); // Setup xmpp stream // // The XMPPStream is the base class for all activity. // Everything else plugs into the xmppStream, such as modules/extensions and delegates. xmppStream = [[XMPPStream alloc] init]; #if !TARGET_IPHONE_SIMULATOR { // Want xmpp to run in the background? // // P.S. - The simulator doesn't support backgrounding yet. // When you try to set the associated property on the simulator, it simply fails. // And when you background an app on the simulator, // it just queues network traffic til the app is foregrounded again. // We are patiently waiting for a fix from Apple. // If you do enableBackgroundingOnSocket on the simulator, // you will simply see an error message from the xmpp stack when it fails to set the property. <span style="color:#66ff99;">xmppStream.enableBackgroundingOnSocket = YES;</span> } #endif // Setup reconnect // // The XMPPReconnect module monitors for "accidental disconnections" and // automatically reconnects the stream for you. // There's a bunch more information in the XMPPReconnect header file. xmppReconnect = [[XMPPReconnect alloc] init]; // Setup roster // // The XMPPRoster handles the xmpp protocol stuff related to the roster. // The storage for the roster is abstracted. // So you can use any storage mechanism you want. // You can store it all in memory, or use core data and store it on disk, or use core data with an in-memory store, // or setup your own using raw SQLite, or create your own storage mechanism. // You can do it however you like! It's your application. // But you do need to provide the roster with some storage facility. xmppRosterStorage = [[XMPPRosterCoreDataStorage alloc] init]; // xmppRosterStorage = [[XMPPRosterCoreDataStorage alloc] initWithInMemoryStore]; xmppRoster = [[XMPPRoster alloc] initWithRosterStorage:xmppRosterStorage]; xmppRoster.autoFetchRoster = YES; xmppRoster.autoAcceptKnownPresenceSubscriptionRequests = YES; // Setup vCard support // // The vCard Avatar module works in conjuction with the standard vCard Temp module to download user avatars. // The XMPPRoster will automatically integrate with XMPPvCardAvatarModule to cache roster photos in the roster. xmppvCardStorage = [XMPPvCardCoreDataStorage sharedInstance]; xmppvCardTempModule = [[XMPPvCardTempModule alloc] initWithvCardStorage:xmppvCardStorage]; xmppvCardAvatarModule = [[XMPPvCardAvatarModule alloc] initWithvCardTempModule:xmppvCardTempModule];</span> // Setup capabilities // // The XMPPCapabilities module handles all the complex hashing of the caps protocol (XEP-0115). // Basically, when other clients broadcast their presence on the network // they include information about what capabilities their client supports (audio, video, file transfer, etc). // But as you can imagine, this list starts to get pretty big. // This is where the hashing stuff comes into play. // Most people running the same version of the same client are going to have the same list of capabilities. // So the protocol defines a standardized way to hash the list of capabilities. // Clients then broadcast the tiny hash instead of the big list. // The XMPPCapabilities protocol automatically handles figuring out what these hashes mean, // and also persistently storing the hashes so lookups aren't needed in the future. // // Similarly to the roster, the storage of the module is abstracted. // You are strongly encouraged to persist caps information across sessions. // // The XMPPCapabilitiesCoreDataStorage is an ideal solution. // It can also be shared amongst multiple streams to further reduce hash lookups. xmppCapabilitiesStorage = [XMPPCapabilitiesCoreDataStorage sharedInstance]; xmppCapabilities = [[XMPPCapabilities alloc] initWithCapabilitiesStorage:xmppCapabilitiesStorage]; xmppCapabilities.autoFetchHashedCapabilities = YES; xmppCapabilities.autoFetchNonHashedCapabilities = NO; // Activate xmpp modules [xmppReconnect activate:xmppStream]; [xmppRoster activate:xmppStream]; [xmppvCardTempModule activate:xmppStream]; [xmppvCardAvatarModule activate:xmppStream]; [xmppCapabilities activate:xmppStream]; // Add ourself as a delegate to anything we may be interested in [xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()]; [xmppRoster addDelegate:self delegateQueue:dispatch_get_main_queue()]; // Optional: // // Replace me with the proper domain and port. // The example below is setup for a typical google talk account. // // If you don't supply a hostName, then it will be automatically resolved using the JID (below). // For example, if you supply a JID like 'user@quack.com/rsrc' // then the xmpp framework will follow the xmpp specification, and do a SRV lookup for quack.com. // // If you don't specify a hostPort, then the default (5222) will be used. // [xmppStream setHostName:@"talk.google.com"]; // [xmppStream setHostPort:5222]; // You may need to alter these settings depending on the server you're connecting to customCertEvaluation = YES; }
ok,let's begin.
1)创建一个XML stream 对象,这货是干嘛的呢。打个比喻:货物运输带,上货和下货 都要靠这条带子。谁让这条带子动起来?
长连接
它就是个马达。
那么这里面的货是啥呢?3种货:美版,港版,日版,偶尔带点国行。(*^__^*) 嘻嘻……,哈哈不开玩笑了。有三种货: 索达斯内!~斯ko一!~是的,好厉害好棒哒!~发现昨天看得RFC6121有点关系啦。~\(≧▽≦)/~啦啦啦 2)是否开启后台模式---NO,除非你有VOIP需要支持,不然后患无穷,现在github 上后台issue还有一大堆没解决的呢,反正呢很复杂哒,我这菜逼就没支持这货 3)开启重连机制(长连接必备,心跳啥的) 开启roster(两种形式:coreData存储 or 开辟内存--临时对象存储),自动获取服务器上的roster数据?是否自动应答 已经存在订阅出席消息的小伙伴的订阅请求,也就是说是否自动过滤掉已经订阅过的订阅或者是已经形成订阅关系的用户请求啦(难点,后面章节细讲)。开启roster CoreDataStorage,也就是数据库存CoreData储技术。 开启vCard(个人信息详情) module,二次封装vCard Module开启,并且启动 vcard对应的coreData 存储技术 开启capabilitie,和与之的存储技术。这货当初看了好久哒,但是现在真忘记了。。。sorry,这块需要找对应的XEP来进行脑补,不过貌似暂时用不到,就让它默认吧。 原文链接传送门 下面是 XMPPFramework的一个核心:multi delegate (作者独有,膜拜!~) 对roster 进行一个sub delegate回调,在当前Class,主线程队列。 关于multi delegate 技术,建议好好看看里面的具体实现,不要求你会写,大概的核心思想能看懂就成,会return BOOL YES or NO 即可。。。 btw1:鄙人对这个multi delegate再次膜拜,当然他写的很多东西,都是让我膜拜的。。比如socket链接。。。XML解析,DDLog。。。反正好多,好了不说了,说多了都是泪,菜狗只能仰望大神。。 btw2:刷刷刷两个小时过去了,洗洗睡了,写blog真心很累。 btw3:服务器那个水?问你呢,你们环境配好了没,我这边要example测试连接了,快给个账号和密码。劳资效率就是这么高,一天搞定基本的数据连接了。 btw4:经理,我这边还算顺利,约有小成,你看这连接界面,成了,虽然界面丑了点,但是能连上服务端了,真棒。 btw5:啪!你个傻蛋,别说这事demo,怎么有你这种队友。 btw6:下期预告
<span style="color:#66ff99;">xmppStream.enableBackgroundingOnSocket</span>
[xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoster addDelegate:self delegateQueue:dispatch_get_main_queue()];
对XML stream 进行添加一个Sub Delegate回调,在当前Class,在mainThread Queue中,

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











Huawei 휴대폰에서 이중 WeChat 로그인을 구현하는 방법은 무엇입니까? 소셜 미디어의 등장으로 WeChat은 사람들의 일상 생활에 없어서는 안될 커뮤니케이션 도구 중 하나가 되었습니다. 그러나 많은 사람들이 동일한 휴대폰에서 동시에 여러 WeChat 계정에 로그인하는 문제에 직면할 수 있습니다. Huawei 휴대폰 사용자의 경우 듀얼 WeChat 로그인을 달성하는 것은 어렵지 않습니다. 이 기사에서는 Huawei 휴대폰에서 듀얼 WeChat 로그인을 달성하는 방법을 소개합니다. 우선, 화웨이 휴대폰과 함께 제공되는 EMUI 시스템은 듀얼 애플리케이션 열기라는 매우 편리한 기능을 제공합니다. 앱 듀얼 오픈 기능을 통해 사용자는 동시에

프로그래밍 언어 PHP는 다양한 프로그래밍 논리와 알고리즘을 지원할 수 있는 강력한 웹 개발 도구입니다. 그중 피보나치 수열을 구현하는 것은 일반적이고 고전적인 프로그래밍 문제입니다. 이 기사에서는 PHP 프로그래밍 언어를 사용하여 피보나치 수열을 구현하는 방법을 소개하고 구체적인 코드 예제를 첨부합니다. 피보나치 수열은 다음과 같이 정의되는 수학적 수열입니다. 수열의 첫 번째와 두 번째 요소는 1이고 세 번째 요소부터 시작하여 각 요소의 값은 이전 두 요소의 합과 같습니다. 시퀀스의 처음 몇 가지 요소

Huawei 휴대폰에서 WeChat 복제 기능을 구현하는 방법 소셜 소프트웨어의 인기와 개인 정보 보호 및 보안에 대한 사람들의 강조가 높아지면서 WeChat 복제 기능이 점차 주목을 받고 있습니다. WeChat 복제 기능을 사용하면 사용자가 동일한 휴대폰에서 여러 WeChat 계정에 동시에 로그인할 수 있으므로 관리 및 사용이 더 쉬워집니다. Huawei 휴대폰에서 WeChat 복제 기능을 구현하는 것은 어렵지 않습니다. 다음 단계만 따르면 됩니다. 1단계: 휴대폰 시스템 버전과 WeChat 버전이 요구 사항을 충족하는지 확인하십시오. 먼저 Huawei 휴대폰 시스템 버전과 WeChat 앱이 최신 버전으로 업데이트되었는지 확인하세요.

PHP 게임 요구사항 구현 가이드 인터넷의 대중화와 발전으로 인해 웹 게임 시장이 점점 더 대중화되고 있습니다. 많은 개발자는 PHP 언어를 사용하여 자신만의 웹 게임을 개발하기를 원하며 게임 요구 사항을 구현하는 것이 핵심 단계입니다. 이 문서에서는 PHP 언어를 사용하여 일반적인 게임 요구 사항을 구현하는 방법을 소개하고 특정 코드 예제를 제공합니다. 1. 게임 캐릭터 만들기 웹게임에서 게임 캐릭터는 매우 중요한 요소입니다. 이름, 레벨, 경험치 등 게임 캐릭터의 속성을 정의하고, 이를 운용할 수 있는 방법을 제공해야 합니다.

오늘날의 소프트웨어 개발 분야에서 효율적이고 간결하며 동시성이 뛰어난 프로그래밍 언어인 Golang(Go 언어)은 점점 더 개발자들의 선호를 받고 있습니다. 풍부한 표준 라이브러리와 효율적인 동시성 기능으로 인해 게임 개발 분야에서 주목받는 선택이 되었습니다. 이 기사에서는 게임 개발에 Golang을 사용하는 방법을 살펴보고 특정 코드 예제를 통해 Golang의 강력한 가능성을 보여줍니다. 1. 게임 개발에서 Golang의 장점 Golang은 정적인 유형의 언어로서 대규모 게임 시스템을 구축하는 데 사용됩니다.

Golang에서 정확한 나눗셈 작업을 구현하는 것은 특히 재무 계산과 관련된 시나리오 또는 고정밀 계산이 필요한 기타 시나리오에서 일반적인 요구 사항입니다. Golang에 내장된 나눗셈 연산자 "/"는 부동 소수점 수에 대해 계산되며 때로는 정밀도가 손실되는 문제가 있습니다. 이 문제를 해결하기 위해 타사 라이브러리나 사용자 정의 기능을 사용하여 정확한 분할 작업을 구현할 수 있습니다. 일반적인 접근 방식은 분수 표현을 제공하고 정확한 나눗셈 연산을 구현하는 데 사용할 수 있는 math/big 패키지의 Rat 유형을 사용하는 것입니다.

실시간 프로그래밍 지침을 제공할 수 없어서 정말 죄송합니다. 하지만 PHP를 사용하여 SaaS를 구현하는 방법을 더 잘 이해할 수 있도록 코드 예제를 제공할 수 있습니다. 다음은 "PHP를 사용하여 SaaS 구현: 종합 분석"이라는 제목의 1,500자 이내의 기사입니다. 오늘날의 정보화 시대에 SaaS(Software as a Service)는 기업과 개인이 소프트웨어에 액세스하는 보다 유연하고 편리한 방법을 제공하는 주류가 되었습니다. SaaS를 사용하면 사용자가 온프레미스에 있을 필요가 없습니다.

제목: Golang을 이용한 데이터 내보내기 기능에 대한 자세한 설명 정보화가 진행됨에 따라 많은 기업과 조직에서는 데이터 분석, 보고서 생성 및 기타 목적을 위해 데이터베이스에 저장된 데이터를 다른 형식으로 내보내야 합니다. 이 기사에서는 Golang 프로그래밍 언어를 사용하여 데이터베이스 연결, 데이터 쿼리 및 데이터를 파일로 내보내기 위한 세부 단계를 포함하여 데이터 내보내기 기능을 구현하는 방법을 소개하고 구체적인 코드 예제를 제공합니다. 먼저 데이터베이스에 연결하려면 da와 같은 Golang에서 제공하는 데이터베이스 드라이버를 사용해야 합니다.
