Asmack源码入门
Smack的初始化涉及到两个步骤: 1.初始化系统属性——通过SmackConfiguration进行系统属性初始化。这些属性可以通过getxxx()方法获
Smack的初始化涉及到两个步骤:
1.初始化系统属性——通过SmackConfiguration进行系统属性初始化。这些属性可以通过getxxx()方法获取。
2.初始化启动类——初始化类意味着在启动时候实例化该类,如果继承SmackInitializer则需要调用initialize()方法。如果不继承SmackInitializer则初始化的操作必须在静态代码块中,一旦加载类时自动执行。
Establishing a Connection创建连接
XmppTCPConnection类是被用来创建连接到xmpp服务器的。
// Create a connection to the jabber.org server._
XMPPConnection conn1 = new XMPPTCPConnection("jabber.org");
conn1.connect();
// Create a connection to the jabber.org server on a specific port._
ConnectionConfigurationconfig = new ConnectionConfiguration("jabber.org", 5222);
XMPPConnection conn2 = new XMPPTCPConnection(config);
conn2.connect();
ConectionConfiguration类提供一些控制操作,譬如是否加密。
Working with the Roster 花名册
Roster可以让你保持获取其他用户的presence状态,用户可以添加进组“Friend”或者“Co-workers”,你可以知晓用户是否在线。
检索roster可以通过XMPPConnection.getRoster()方法,roster类允许你查看所有的roster enteries ,群组信息当前的登录状态。
Reading and WritingPackets读写数据包
XMPP服务器和客户端间以XML传递的信息被称为数据包。
org.jivesoftware.smack.packet包内有三种封装好的基本的packet,分别是message, presence和IQ。
比如Chat和GroupChat类提供了更高级别的结构用以创建发送packet,当然你也可以直接用packet。
// Create a new presence. Pass in false to indicate we're unavailable._
Presence presence = new Presence(Presence.Type.unavailable);
presence.setStatus("Gone fishing");
// Send the packet (assume we have aXMPPConnection instance called "con").
con.sendPacket(presence);
Smack提供两种读取packets
PacketListener和PacketCollector,这两种都通过PacketFilter进行packet加工。
A packet listener is used for event style programming, while a packet collector has a result queue of packets that you can do polling and blocking operations on.
(packet listener事件监听,而packet collector是一个packets的可以进行polling和blocking操作的结果集队列。)
So, a packet listener is useful when you want to take some action whenever a packet happens to come in, while a packet collector is useful when you want to wait for a specific packet to arrive.
(packet listener一旦数据包传递抵达的时候你可以进行处理,packet collector则被使用在你需要等待一个指定的packet传递抵达时候。)
Packet collectors and listeners can be created using an Connection instance.
(packet listener和packet collector在connection实例中被创建。)
// Create a packet filter to listen for new messages from a particular
// user. We use an AndFilter to combine two other filters._
PacketFilter filter = new AndFilter(new PacketTypeFilter(Message.class),
newFromContainsFilter("mary@jivesoftware.com"));
// Assume we've created a XMPPConnection name "connection".
// First, register a packet collector using the filter we created.
PacketCollectormyCollector = connection.createPacketCollector(filter);
// Normally, you'd do something with the collector, like wait for new packets.
// Next, create a packet listener. We use an anonymous inner class for brevity.
PacketListenermyListener = new PacketListener() {
public void processPacket(Packet packet) {
// Do something with the incoming packet here._
}
};
// Register the listener._
connection.addPacketListener(myListener, filter);
Managing Connection
Connect and disConnect
// Create the configuration for this new connection_
ConnectionConfigurationconfig = new ConnectionConfiguration("jabber.org", 5222);
AbstractXMPPConnection connection = new XMPPTCPConnection(config);
// Connect to the server_
connection.connect();
// Log into the server_
connection.login("username", "password", "SomeResource");
...
// Disconnect from the server_
connection.disconnect();
Messaging using Chat
Chat
org.jivesoftware.smack.Chat
// Assume we've created a XMPPConnection name "connection"._
ChatManagerchatmanager = connection.getChatManager();
Chat newChat = chatmanager.createChat("jsmith@jivesoftware.com", new MessageListener() {
public void processMessage(Chat chat, Message message) {
System.out.println("Received message: " + message);
}
});
try {
newChat.sendMessage("Howdy!");
}
catch (XMPPException e) {
System.out.println("Error Delivering block");
}
Message newMessage = new Message();
newMessage.setBody("Howdy!");
message.setProperty("favoriteColor", "red");
newChat.sendMessage(newMessage);
// Assume a MessageListener we've setup with a chat._
public void processMessage(Chat chat, Message message) {
// Send back the same text the other user sent us._
chat.sendMessage(message.getBody());
}
incoming Chat
_// Assume we've created a XMPPConnection name "connection"._
ChatManagerchatmanager = connection.getChatManager().addChatListener(
newChatManagerListener() {
@Override
public void chatCreated(Chat chat, booleancreatedLocally)
{
if (!createdLocally)
chat.addMessageListener(new MyNewMessageListener());;
}
});
Roster and Presence
roster entries
包含xmpp地址,备注名,群组(假如该用户不属于任何一组,则调用“unfiled entry”):
Roster roster = connection.getRoster();
Collection
for (RosterEntry entry : entries) {
System.out.println(entry);
}
监听roster和presence更改:
Roster roster = con.getRoster();
roster.addRosterListener(new RosterListener() {
// Ignored events public void entriesAdded(Collection
public void entriesDeleted(Collection
public void entriesUpdated(Collection
public void presenceChanged(Presence presence) {
System.out.println("Presence changed: " + presence.getFrom() + " " + presence);
}
});
Provider architecture
smack provider是用于解析packet extension 和 IQ xml流的,有两种类型的provider:
IQProvider -parses IQ request into java objects
Extension Provider - parses XML sub-documents attached to packets into PacketExtension instances. By default, Smack only knows how to process a few standard packets and sub-packets that are in a few namespaces such as:
(解析packet的xml子元素到PacketExtension实例中。Smack默认仅知道处理少数的标准packets和少数的指定的namespaces下的子packets)

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

Diffusion不仅可以更好地模仿,而且可以进行「创作」。扩散模型(DiffusionModel)是一种图像生成模型。与此前AI领域大名鼎鼎的GAN、VAE等算法,扩散模型另辟蹊径,其主要思想是一种先对图像增加噪声,再逐步去噪的过程。其中如何去噪还原原图像是算法的核心部分。最终算法能够从一张随机的噪声图像中生成图像。近年来,生成式AI的惊人增长将文本转换为图像生成、视频生成等领域的许多令人兴奋的应用提供了支持。这些生成工具背后的基本原理是扩散的概念,这是一种特殊的采样机制,克服了以前的方法中被

Kimi:一句话,十几秒钟,一份PPT就新鲜出炉了。PPT这玩意儿,可太招人烦了!开个碰头会,要有PPT;写个周报,要做PPT;拉个投资,要展示PPT;就连控诉出轨,都得发个PPT。大学更像是学了个PPT专业,上课看PPT,下课做PPT。或许,37年前丹尼斯・奥斯汀发明PPT时也没想到,有一天PPT竟如此泛滥成灾。吗喽们做PPT的苦逼经历,说起来都是泪。「一份二十多页的PPT花了三个月,改了几十遍,看到PPT都想吐」;「最巅峰的时候,一天做了五个PPT,连呼吸都是PPT」;「临时开个会,都要做个

北京时间6月20日凌晨,在西雅图举办的国际计算机视觉顶会CVPR2024正式公布了最佳论文等奖项。今年共有10篇论文获奖,其中2篇最佳论文,2篇最佳学生论文,另外还有2篇最佳论文提名和4篇最佳学生论文提名。计算机视觉(CV)领域的顶级会议是CVPR,每年都会吸引大量研究机构和高校参会。据统计,今年共提交了11532份论文,2719篇被接收,录用率为23.6%。根据佐治亚理工学院对CVPR2024的数据统计分析,从研究主题来看,论文数量最多的是图像和视频合成与生成(Imageandvideosyn

C语言作为一门广泛应用的编程语言,对于想从事计算机编程的人来说是必学的基础语言之一。然而,对于初学者来说,学习一门新的编程语言可能会有些困难,尤其是缺乏相关的学习工具和教材。在本文中,我将介绍五款帮助初学者入门C语言的编程软件,帮助你快速上手。第一款编程软件是Code::Blocks。Code::Blocks是一个免费的开源集成开发环境(IDE),适用于

标题:技术入门者必看:C语言和Python难易程度解析,需要具体代码示例在当今数字化时代,编程技术已成为一项越来越重要的能力。无论是想要从事软件开发、数据分析、人工智能等领域,还是仅仅出于兴趣学习编程,选择一门合适的编程语言是第一步。而在众多编程语言中,C语言和Python作为两种广泛应用的编程语言,各有其特点。本文将对C语言和Python的难易程度进行解析

我们知道LLM是在大规模计算机集群上使用海量数据训练得到的,本站曾介绍过不少用于辅助和改进LLM训练流程的方法和技术。而今天,我们要分享的是一篇深入技术底层的文章,介绍如何将一堆连操作系统也没有的「裸机」变成用于训练LLM的计算机集群。这篇文章来自于AI初创公司Imbue,该公司致力于通过理解机器的思维方式来实现通用智能。当然,将一堆连操作系统也没有的「裸机」变成用于训练LLM的计算机集群并不是一个轻松的过程,充满了探索和试错,但Imbue最终成功训练了一个700亿参数的LLM,并在此过程中积累

许多游戏玩家遇到了游戏无法初始化图形系统的令人沮丧的问题。这篇文章将深入探讨这个问题背后的常见原因,并找到简单而有效的解决方案,让你重新回到棋盘上,并在任何时间内通过关卡。因此,如果你在过山车大亨、刺客信条、托尼·霍克的职业溜冰者等中收到无法初始化图形系统错误信息,请遵循本文中提到的解决方案。初始化错误无法初始化图形系统。不支持显卡。修复无法初始化图形系统错误信息要解决过山车大亨、刺客信条、托尼·霍克的专业溜冰者等游戏中的无法初始化图形系统错误,可以尝试执行以下解决方法:更新显卡驱动程序在兼容模

检索增强式生成(RAG)是一种使用检索提升语言模型的技术。具体来说,就是在语言模型生成答案之前,先从广泛的文档数据库中检索相关信息,然后利用这些信息来引导生成过程。这种技术能极大提升内容的准确性和相关性,并能有效缓解幻觉问题,提高知识更新的速度,并增强内容生成的可追溯性。RAG无疑是最激动人心的人工智能研究领域之一。有关RAG的更多详情请参阅本站专栏文章《专补大模型短板的RAG有哪些新进展?这篇综述讲明白了》。但RAG也并非完美,用户在使用时也常会遭遇一些「痛点」。近日,英伟达生成式AI高级解决
