xmpp发送文件
xmpp 文件传输协议:
- XEP-0096: SI File Transfer:文件传输流初始化协议
- XEP-0065: SOCKS5 Bytestreams:带外socks5代理字节流传输协议
- XEP-0047: In-Band Bytestreams:带内字节流传输协议
- XEP-0066: Out of Band Data:带外数据传输协议
- XEP-0030: Service Discovery:服务发现协议
- XEP-0096:文件传输流初始化协议。支持断点续传。当file元素包含range无素时,range包含offset、length两个属性,可以指出要传送的数据位于文件的什么位置。
- xep-0047:是把数据进行base64编码后,放到iq消息中转发。这个适用于小数据传输。
- xep-0066:带外数据传输,是从发送端拉取。这个需要发送端位于公网。
- xep-0065:带外数据传输,如果发送端位于公网,则接收端直接连接发送端拉取数据。如果双方都位于内网,则双方连接代理服务器,通过代理服务器转发数据。
- XEP-0030:服务发现协议,这里用来发现代理服务。
xep-0065 协议:
直接连接流程:
Requester Target
| |
| Send S5B initiation request |
| -----------------------------> |
| |
| Open TCP socket |
| <_____________________________ |
| |
| Request SOCKS5 connection |
| <\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ |
| |
| Acknowledge SOCKS5 connection |
| /////////////////////////////> |
| |
| Send S5B acceptance |
| <----------------------------- |
| |
| Exchange data over S5B |
| <============================> |
| |
间接连接流程:
Requester Proxy Target
| | |
| Send S5B initiation request |
| --------------------------------------------------------------> |
| | |
| | Open TCP socket |
| | <_____________________________ |
| | |
| | Request SOCKS 5 connection |
| | <\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ |
| | |
| | Acknowledge SOCKS 5 connection |
| | /////////////////////////////> |
| | |
| Send S5B acceptance |
| <-------------------------------------------------------------- |
| | |
| Open TCP socket | |
| _____________________________> | |
| | |
| Request SOCKS 5 connection | |
| /////////////////////////////> | |
| | |
| Acknowledge SOCKS 5 connection | |
| <\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ | |
| | |
| Request activation | |
| -----------------------------> | |
| | |
| Acknowledge activation | |
| <----------------------------- | |
| | |
| Exchange data over S5B |
| <=============================================================> |
| | |
qxmpp 文件传输:
qxmpp中的文件传输实现了:
- XEP-0096: SI File Transfer
- XEP-0047: In-Band Bytestreams
- XEP-0065: SOCKS5 Bytestreams
- XEP-0030: Service Discovery
QXmppTransferManager:实现XEP-0096、XEP-0047、XEP-0065
QXmppDiscoveryManager:实现 XEP-0030
实例:
流初始化过程(XEP-0096):
发送端:<iq id="qxmpp73" to="c@rabbitim.com/QXmpp" type="set">
<si xmlns="http://jabber.org/protocol/si"
id="MsVtTkTuwqKQhMBxUsuM66qLgEG9r4Cr"
profile="http://jabber.org/protocol/si/profile/file-transfer">
<file xmlns="http://jabber.org/protocol/si/profile/file-transfer"
date="2009-07-14T04:52:25.650Z"
hash="076e3caed758a1c18c91a0e9cae3368f"
name="Chrysanthemum.jpg"
size="879394"/>
<feature xmlns="http://jabber.org/protocol/feature-neg">
<x xmlns="jabber:x:data" type="form">
<field type="list-single" var="stream-method">
<option><value>http://jabber.org/protocol/ibb</value></option>
<option><value>http://jabber.org/protocol/bytestreams</value></option>
</field>
</x>
</feature>
</si>
</iq>
目标端:
<iq id="qxmpp73" to="b@rabbitim.com/QXmpp" type="result" from="c@rabbitim.com/QXmpp">
<si xmlns="http://jabber.org/protocol/si"
profile="http://jabber.org/protocol/si/profile/file-transfer">
<feature xmlns="http://jabber.org/protocol/feature-neg">
<x xmlns="jabber:x:data" type="submit">
<field type="list-single" var="stream-method">
<value>http://jabber.org/protocol/bytestreams</value>
</field>
</x>
</feature>
</si>
</iq>
查询代理过程(XEP-0030):
发送端:
服务器回复信息,告知可用的代理:
<iq type="result" id="qxmpp74" to="b@rabbitim.com/QXmpp">
<query xmlns="http://jabber.org/protocol/disco#items">
<item jid="proxy.rabbitim.com" name="Socks 5 Bytestreams Proxy"/>
<item jid="pubsub.rabbitim.com" name="Publish-Subscribe service"/>
<item jid="conference.rabbitim.com" name="公共房间"/>
<item jid="search.rabbitim.com" name="User Search"/>
</query>
</iq>
这个代理查询过程,qxmpp有单独的类实现,查询到的结果用 QXmppTransferManager::setProxy 告知 QXmppTransferManager
得到代理配置过程: 这里选择name=“Socks 5 Bytestreams Proxy”的代理,初始方给这个代理发送信息获取代理连接信息
发送端:
代理:
<iq type="result" id="qxmpp75" from="proxy.rabbitim.com" to="b@rabbitim.com/QXmpp">
<query xmlns="http://jabber.org/protocol/bytestreams">
<streamhost jid="proxy.rabbitim.com" host="182.254.185.29" port="7777"/>
</query>
</iq>
连接代理过程(XEP-0065):
发送端:
这里的 streamhost 是有顺序关系的。主机地址放在最前,代理放在最后。目标端会接这个顺序去连接。如果前面的可以连接上,就不在做后面的。 这个可以保证先直接连接,只有在直接连接不成功后,才连接代理,进行转发。
目标端: 目标端按上一步发过来的信息,按照streamhost的顺序连接。如果成功,则返回下面信息通知发送端。
<iq id="qxmpp77" to="b@rabbitim.com/QXmpp" type="result" from="c@rabbitim.com/QXmpp">
<query xmlns="http://jabber.org/protocol/bytestreams"
sid="MsVtTkTuwqKQhMBxUsuM66qLgEG9r4Cr" mode="tcp">
<streamhost-used jid="proxy.rabbitim.com"/>
</query>
</iq>
发送端激活代理: 发送端:
c@rabbitim.com/QXmpp
代理:
<iq type="result" id="qxmpp79" from="proxy.rabbitim.com" to="b@rabbitim.com/QXmpp"/>
OpenFire 中的文件传输设置:
文件代理有下面几个设置:
- xmpp.filetransfer.enabled = true
- xmpp.proxy.service=proxy
- xmpp.proxy.enabled=ture
- xmpp.proxy.port=7777
- xmpp.proxy.externalip=127.0.0.1
上面这几个后面的值是默认值。前面四个用默认值就可以了,但最后一个需要设置为代理服务器的外网地址。 而代理服务器的jid:
proxyServiceName = JiveGlobals.getProperty("xmpp.proxy.service", "proxy");
/**
* Returns the fully-qualifed domain name of this chat service.
* The domain is composed by the service name and the
* name of the XMPP server where the service is running.
*
* @return the file transfer server domain (service name + host name).
*/
public String getServiceDomain() {
return proxyServiceName + "." + XMPPServer.getInstance().getServerInfo().getXMPPDomain();
}
public JID getAddress() {
return new JID(null, getServiceDomain(), null);
}
所以,文件代理服务器的jid为下面两个配置值的组合: xmpp.proxy.service、xmpp.domain
文件传输的代码位于源码目录: src/java/org/jivesoftware/openfire/filetransfer
总结:
- 配置域名:xmpp.domain为rabbitim.com
- 配置扩展IP:xmpp.proxy.externalip为文件代理服务器的外网ip
- 客户端程序查询到代理后,在发送文件前,要调用 QXmppTransferManager::setProxy 设置代理。 本程序为:m_TransferManager.setProxy("proxy.rabbitim.com");
xmpp发送文件的更多相关文章
- ios xmpp 发送语音图片解决方案
ios xmpp 发送语音,图片解决方案,有需要的朋友可以参考下. 目前做IM多是用的xmpp. 因为项目需求需要实现语音和图片的发送. 发送语音图片有三种方法. 1,xmpp smack.文件传输方 ...
- win7系统下的飞秋发送文件失败问题
飞秋发送文件失败这个问题大多数是由防火墙引起的1.检查windows自带的防火墙设置,在左侧的"允许程序通过windows防火墙"查看飞秋是否存在,不存在则增加之,公网.专网都勾选 ...
- 利用Socket远程发送文件
思想: 1.注意使用两个通道,一个普通对象通信通道,另一个纯净的文件字节流通道 2.利用通信通道发送文件请求,新建字节流通道,开始发送文件
- [转]C#网络编程(订立协议和发送文件) - Part.4
本文转自:http://www.tracefact.net/CSharp-Programming/Network-Programming-Part4.aspx 源码下载:http://www.trac ...
- android开发,socket发送文件,read阻塞,得不到文件尾-1
这是我的接收文件代码:开始可以读取到-1,但是现在又读取不到了,所以才加上红色字解决的(注释的代码) File file = new File(mfilePath,"chetou." ...
- tengine lua 开源一 调用内部接口高效发送文件
tengine lua 开源一 调用内部接口高效发送文件 开源自己封装的sendfile 模块,可以高效的通过lua发送文件 源码地址:https://github.com/weinyzhou/Lu ...
- ASP.NET MVC:通过 FileResult 向 浏览器 发送文件
在 Controller 中我们可以使用 FileResult 向客户端发送文件. FileResult FileResult 是一个抽象类,继承自 ActionResult.在 System.Web ...
- socket(TCP)发送文件
一:由于在上一个随笔的基础之上拓展的所以直接上代码,客户端: using System; using System.Collections.Generic; using System.Componen ...
- C#_Socket网络编程实现的简单局域网内即时聊天,发送文件,抖动窗口。
最近接触了C#Socket网络编程,试着做了试试(*^__^*) 实现多个客户端和服务端互相发送消息 发送文件抖动窗口功能 服务端: using System; using System.Collec ...
随机推荐
- Popular Deep Learning Tools – a review
Popular Deep Learning Tools – a review Deep Learning is the hottest trend now in AI and Machine Lear ...
- 自制SCVMM 模板成功
其实,如果通过SCVMM 的PS命令来创建虚拟机的话,模板的意义也不是特别大. 其它的PROFILE和硬件配置都会被替换掉的. ~~~~~~~~~~~~~~~ Windows模版 一. 准备OS的VH ...
- bit、sbin、sfr、sfr16 区别分析
1.bit 和 sbit 都是 C51 扩展的变量类型. bit 和 int char 之类的差不多,只不过 char=8 位, bit=1 位而已.都是变量,编译器在编译过程中分配地址.除非你指定, ...
- 执行计划中常见index访问方式(转)
近期有朋友对于单个表上的index各种情况比较模糊,这里对于单个表上,单个index出现的大多数情况进行了总结性测试,给出了测试结果,至于为什么出现这样的试验结果未做过多解释,给读者留下思考的空间.本 ...
- setjmp/longjmp 使用
C语言中有一个goto语句,其可以结合标号实现函数内部的任意跳转(通常情况下,很多人都建议不要使用goto语句,因为采用goto语句后,代码维护工作量加大).另外,C语言标准中还提供一种非局部跳转“n ...
- 利用函数索引优化<>
SQL> select count(*),ID from test_2 group by id; COUNT(*) ID ---------- ---------- 131072 1 11796 ...
- java学习面向对象之static内存图解
上一节当中描述了static的用法,以及成员变量和静态变量的区别.但是static除了可以修饰成员变量使之成为静态变量外,他还可以同时修饰函数,使之成为静态函数,我们来看一个例子: class Sta ...
- iOS应用架构浅谈
(整理至http://www.cocoachina.com/ios/20150414/11557.html) 缘由 从事iOS工作一年多了,主要从事QQ钱包SDK开发和财付通app维护,随着对业务的慢 ...
- 吐血原创:mini2440和win7笔记本利用无路由功能的交换机共享上网(使用x-router软路由)
真的是要吐血了,为了使自己的win7系统笔记本和mini2440,通过交换机(没有路由功能,才5口,和HUB差不多)共享宽带上网,并且连接上的宽带还是长城宽带,我用尽各种cmd命令都查不到长城宽带的默 ...
- [Locked] Paint Fence
Paint Fence There is a fence with n posts, each post can be painted with one of the k colors. You ha ...