XMPP之文件传输报文

最近在做文件传输,遇到只能发送文件到spark,spark发送文件来不能接收,要么一直等待,要么发一下就要重试,这天终于找到问题的所在了
我的openfire里面的:服务器->服务器设置->文件传输设置 里面的代理服务被禁用了,应该要使用里面的“使用”

这是我同学总结分析出来的传输文件的报文,由于我们两个是一起在做,我就不去抓了,为了记笔记不得不发一下

发送文件场景:
1,对方拒接
2,对方同意接受
	2.1对方中途中断接收
	2.2我方中途中断发送
	2.3发送成功

------------------------------拒绝接受

A请求向B发送一个文件
<iq type='set' to='lxy2@user-20160421db/Spark' id='file_33fe4dbdf2364' xmlns='jabber:client'>
	<si xmlns='http://jabber.org/protocol/si' id='jsi_33fe4dbdf2313' profile='http://jabber.org/protocol/si/profile/file-transfer' mime-type='application/pdf'>
		<file xmlns='http://jabber.org/protocol/si/profile/file-transfer' name='File (2).pdf' size='457701'/>
		<feature xmlns='http://jabber.org/protocol/feature-neg'>
			<x xmlns='jabber:x:data' type='form'>
				<field var='stream-method' type='list-single'>
					<option>
						<value>http://jabber.org/protocol/ibb</value>
					</option>
				</field>
			</x>
		</feature>
	</si>
</iq>

B拒绝
<iq xmlns="jabber:client" id="file_33fe4dbdf2364" to="lxy@user-20160421db/8xz8uslghx" from="lxy2@user-20160421db/Spark" type="error">
	<error code="406" type="MODIFY">
		not-acceptable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
	</error>
</iq>


------------------------------------同意接受,并完成发送
A请求向B发送一个文件。包含一些文件的信息,以及发送文件所使用的stream-method,提供了option,可选项,这里
实现了ibb方式,所以只提供这种方式。
<iq type='set' to='lxy2@user-20160421db/Spark' id='file_33fe66c647645' xmlns='jabber:client'>
	<si xmlns='http://jabber.org/protocol/si' id='jsi_33fe66c647209' profile='http://jabber.org/protocol/si/profile/file-transfer' mime-type='application/pdf'>
		<file xmlns='http://jabber.org/protocol/si/profile/file-transfer' name='File (1).pdf' size='1073243'/>
		<feature xmlns='http://jabber.org/protocol/feature-neg'>
			<x xmlns='jabber:x:data' type='form'>
				<field var='stream-method' type='list-single'>
					<option>	
						<value>http://jabber.org/protocol/ibb</value>
					</option>
				</field>
			</x>
		</feature>
	</si>
</iq>

B同意接收文件,同时也指明了使用ibb方式
<iq xmlns="jabber:client" id="file_33fe66c647645" to="lxy@user-20160421db/8xz8uslghx" from="lxy2@user-20160421db/Spark" type="result">
	<si xmlns="http://jabber.org/protocol/si">
		<feature xmlns="http://jabber.org/protocol/feature-neg">
			<x xmlns="jabber:x:data" type="submit">
				<field var="stream-method">
					<value>http://jabber.org/protocol/ibb</value>
				</field>
			</x>
		</feature>
	</si>
</iq>


A发送一个open表示初始化了通道,并通知对方,每一块的data大小为4096(当然,这是指最大的,最后一块可能没有4096)
<iq type='set' to='lxy2@user-20160421db/Spark' id='efd57f0e-ba5a-4cbe-b68b-d7e1353839c2:ibb' xmlns='jabber:client'>
	<open xmlns='http://jabber.org/protocol/ibb' stanza='iq' sid='jsi_33fe66c647209' block-size='4096'/>
</iq>

B回发一个result表示接受。
<iq xmlns="jabber:client" id="efd57f0e-ba5a-4cbe-b68b-d7e1353839c2:ibb" to="lxy@user-20160421db/8xz8uslghx" from="lxy2@user-20160421db/Spark" type="result"/>

A接着将发送多次的data,直至将数据发送完毕。注意:data中的seq是发送的第几块数据
<iq type='set' to='lxy2@user-20160421db/Spark' id='b8ef6e92-66c8-41f9-aa16-711d471b5b7a:ibb' xmlns='jabber:client'>
	<data xmlns='http://jabber.org/protocol/ibb' seq='0' sid='jsi_33fe66c647209'>数据在这里</data>
</iq>

B回复一个iq result表示收到上面的data。注意,只有收到B的这个回复,A才会发送下一个data。
<iq xmlns="jabber:client" id="b8ef6e92-66c8-41f9-aa16-711d471b5b7a:ibb" to="lxy@user-20160421db/8xz8uslghx" from="lxy2@user-20160421db/Spark" type="result"/>

...经过多次发送,数据发送完成

A将会发送一个close告诉B,数据已经发送完毕了
<iq type='set' to='lxy2@user-20160421db/Spark' id='f113f9f8-619b-4446-8551-3e85d7bbd065:ibb' xmlns='jabber:client'>
	<close xmlns='http://jabber.org/protocol/ibb' sid='jsi_33fe66c647209'/>
</iq>

B回复一个iq result表示知道了
<iq xmlns="jabber:client" id="f113f9f8-619b-4446-8551-3e85d7bbd065:ibb" to="lxy@user-20160421db/8xz8uslghx" from="lxy2@user-20160421db/Spark" type="result"/>



------------------------------------同意接受,但A中断发送
前面代码一样的

A发送一个close强制中断发送
<iq type='set' to='lxy2@user-20160421db/Spark' id='25384610-3cb2-4b21-8017-cde4d33fed07:ibb' xmlns='jabber:client'>
	<close xmlns='http://jabber.org/protocol/ibb' sid='jsi_33fe9304c6907'/>
</iq>

B返回iq result确认
<iq xmlns="jabber:client" id="ff5767cb-7677-43e8-9e9c-ae7493ab7a04:ibb" to="lxy@user-20160421db/76xgw7w2r6" from="lxy2@user-20160421db/Spark" type="result"/>

------------------------------------同意接受,但B中断接收
前面代码一样

B发送来一个close强制中断接收
<iq xmlns="jabber:client" id="pfVx0-912" to="lxy@user-20160421db/76xgw7w2r6" type="set" from="lxy2@user-20160421db/Spark">
	<close xmlns="http://jabber.org/protocol/ibb" sid="jsi_33fe9702f3329"/>
</iq>

A确认收到并停止继续发送
<iq type='result' to='lxy2@user-20160421db/Spark' id='pfVx0-912' xmlns='jabber:client'/>
  

  

posted on 2017-03-30 22:23  丨丿丶  阅读(416)  评论(0编辑  收藏  举报