我们已经使用新的Android 4.1.1实现了FileTransfer功能。 除了将文件传输到iphone客户端外,每件事情都可以正常工作。转移在谈判时失败。
使用Windows smack客户端传输成功时,我们会收到以下日志。
D/SMACK(25089): SENT (0): <iq to='yeryes@192.168.100.239/QXmpp' id='tmfCy-335' type='set'><si xmlns='http://jabber.org/protocol/si' id='jsi_1094412687185521586' mime-type='image/jpeg' profile='http://jabber.org/protocol/si/profile/file-transfer'><file xmlns="http://jabber.org/protocol/si/profile/file-transfer" name="5_224724.jpg" size="630784" ><desc>normal</desc></file><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/bytestreams</value></option><option><value>http://jabber.org/protocol/ibb</value></option></field></x></feature></si></iq>
D/SMACK(25089): RECV (0): <iq from='yeryes@192.168.100.239/QXmpp' to='pgunjasfv@192.168.100.239/Tablet' id='tmfCy-335' type='result'><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>
D/SMACK(25089): SENT (0): <iq to='192.168.100.239' id='tmfCy-341' type='get'><query xmlns='http://jabber.org/protocol/disco#items'></query></iq>
D/SMACK(25089): SENT (0): <iq to='yeryes@192.168.100.239/QXmpp' id='tmfCy-353' type='set'><query xmlns='http://jabber.org/protocol/bytestreams' sid='jsi_1094412687185521586' mode='tcp'><streamhost jid='pgunjasfv@192.168.100.239/Tablet' host='192.168.100.133' port='7777'/><streamhost jid='pgunjasfv@192.168.100.239/Tablet' host='fe80::5cf8:a1ff:fe8b:b73b%p2p0' port='7777'/><streamhost jid='pgunjasfv@192.168.100.239/Tablet' host='fe80::5ef8:a1ff:fe8b:b73b%wlan0' port='7777'/><streamhost jid='proxy.192.168.100.239' host='192.168.100.239' port='7777'/></query></iq>
D/SMACK(25089): RECV (0): <iq from='yeryes@192.168.100.239/QXmpp' to='pgunjasfv@192.168.100.239/Tablet' id='tmfCy-353' type='result'><query xmlns='http://jabber.org/protocol/bytestreams' sid='jsi_1094412687185521586'><streamhost-used jid='pgunjasfv@192.168.100.239/Tablet'/></query></iq>
D/SMACK(25089): RECV (0): <iq from='192.168.100.239' to='pgunjasfv@192.168.100.239/Tablet' id='4072246770' type='get'><ping xmlns='urn:xmpp:ping'/></iq>
D/SMACK(25089): SENT (0): <iq to='192.168.100.239' id='4072246770' type='result'></iq>
&#13;
当使用iphone smack客户端传输失败时,我们会收到以下日志:
D/SMACK(25089): SENT (0): <iq to='iphone@192.168.100.239/iPad' id='tmfCy-441' type='set'><si xmlns='http://jabber.org/protocol/si' id='jsi_1968597579584741254' mime-type='image/jpeg' profile='http://jabber.org/protocol/si/profile/file-transfer'><file xmlns="http://jabber.org/protocol/si/profile/file-transfer" name="5_224724.jpg" size="630784" ><desc>normal</desc></file><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/bytestreams</value></option><option><value>http://jabber.org/protocol/ibb</value></option></field></x></feature></si></iq>
D/SMACK(25089): RECV (0): <iq from='iphone@192.168.100.239/iPad' to='pgunjasfv@192.168.100.239/Tablet' type='result' id='tmfCy-441'><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/bytestreams</value></field></x></feature></si></iq>
D/SMACK(25089): SENT (0): <iq to='iphone@192.168.100.239/iPad' id='tmfCy-443' type='get'><query xmlns='http://jabber.org/protocol/disco#info'></query></iq>
D/SMACK(25089): RECV (0): <iq from='iphone@192.168.100.239/iPad' to='pgunjasfv@192.168.100.239/Tablet' type='error' id='tmfCy-443'><query xmlns='http://jabber.org/protocol/disco#info'/><error type='cancel' code='501'><feature-not-implemented xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></iq>
&#13;
通过比较日志,我觉得设置一个不正确的xmpp登录连接代理问题。
XMPP登录代码:
ProxyInfo proxy = new ProxyInfo(null, loc_IP, 7777, null,null);
我真的很想以这种方式使用它,
ProxyInfo proxy = new ProxyInfo(ProxyType.SOCKS5, loc_IP, 7777, null,null);
,但登录过程失败。
= XMPPTCPConnectionConfiguration.builder()
.setProxyInfo(proxy)
.setServiceName(loc_IP)
.setHost(loc_IP)
.setPort(XMPP_PORT)
.setCompressionEnabled(false)
.setDebuggerEnabled(true)
.setCustomSSLContext(sslContext)
.setSecurityMode(SecurityMode.ifpossible)
.setHostnameVerifier(verifier)
.setUsernameAndPassword(username, pwd)
.setResource(resourcestring)
.build();
启用服务代码的文件传输:
ServiceDiscoveryManager sdm=ServiceDiscoveryManager.getInstanceFor(main.login.connection);
if (sdm == null) {
sdm = ServiceDiscoveryManager.getInstanceFor(main.login.connection);
sdm.addFeature("http://jabber.org/protocol/disco#info");
sdm.addFeature("jabber:iq:privacy");
sdm.removeFeature("http://jabber.org/protocol/ibb");
}
SmackConfiguration.DEBUG = true;
// FileTransfer Service
ProviderManager.addIQProvider("query",
"http://jabber.org/protocol/bytestreams",new BytestreamsProvider());
ProviderManager.addIQProvider("query",
"http://jabber.org/protocol/disco#items",new DiscoverItemsProvider());
ProviderManager.addIQProvider("query",
"http://jabber.org/protocol/disco#info",new DiscoverInfoProvider());
ProviderManager.addIQProvider("si","http://jabber.org/protocol/si",new StreamInitiationProvider());
fileTransferNegotiator = FileTransferNegotiator.getInstanceFor(main.login.connection);
fileTransferNegotiator.IBB_ONLY = false;
fileTransferManager = FileTransferManager.getInstanceFor(main.login.connection);
fileTransferManager.addFileTransferListener(fileTransferListener);
fileTransferListener =new FileTransferListener() {
@Override
public void fileTransferRequest(FileTransferRequest request) {
IncomingFileTransfer inComingFileTransfer = request.accept();
//followed by status handling code in a thread
}
};
&#13;
答案 0 :(得分:0)
以下设置帮助我实现了一对一的文件传输:
我们需要创建一个基于Socks5的文件传输监听器,在iphone和android之间进行文件传输时会出现问题。
1)由于文件传输是通过WIFI进行的,因此Android包括所有类型的ip:ipV4 + ipv6(如果在设备中可用),因此我们需要删除任何ipv6类型地址或空白0.0的默认代理设置。 0.0类型地址。 2)我们没有正确实现代理,需要实现socks5代理设置。
最后,这些是连接配置的设置。
//XMPP Connection Setup
connConfig = XMPPTCPConnectionConfiguration
.builder()
.setServiceName(loc_IP)
.setHost(loc_IP)
.setPort(XMPP_PORT)
.setCompressionEnabled(false)
.setDebuggerEnabled(true)
.setCustomSSLContext(sslContext)
.setSecurityMode(SecurityMode.disabled)
.setHostnameVerifier(verifier)
.setUsernameAndPassword(nick_Name, password)
.setResource(resourcestring)
.build();
SmackConfiguration.setDefaultPacketReplyTimeout(50000);
Socks5Proxy.setLocalSocks5ProxyEnabled(false);
Socks5Proxy.setLocalSocks5ProxyPort(7777);
removeAbnormalIP();
SASLPlainMechanism saslPlainMechanism = new SASLPlainMechanism();
SASLAuthentication.registerSASLMechanism(saslPlainMechanism);
CXmppFileTransferManager xmppFileManager = main.getXMPPTransferManager();
xmppFileManager.serviceEnabledForXmppFileTransfer();
////////////////////////////////////////////////////////////////////////
private void removeAbnormalIP() {
WifiManager wifiManager = (WifiManager) main.currentContext.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
Socks5Proxy mProxy = Socks5Proxy.getSocks5Proxy();
List<String> addresses = new ArrayList<String>();
if (wifiInfo != null) {
int ipAddress = wifiInfo.getIpAddress();
String strIPAddess = ((ipAddress >> 0) & 0xFF) + "."
+ ((ipAddress >> 8) & 0xFF) + "."
+ ((ipAddress >> 16) & 0xFF) + "."
+ ((ipAddress >> 24) & 0xFF);
// ignore "0.0.0.0"
if (!strIPAddess.equals("0.0.0.0"))
addresses.add(strIPAddess);
}
// set an ip in case there is a Wifi Connection
// otherwise addresses will be empty and local S5B proxy will not be
// used
mProxy.replaceLocalAddresses(addresses);
}
/////////////////////////////////////////////////////////////////////
XmppFileTransferManager Class:
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(main.login.connection);
if (sdm == null) {
sdm = ServiceDiscoveryManager.getInstanceFor(main.login.connection);
sdm.addFeature("http://jabber.org/protocol/disco#info");
sdm.addFeature("jabber:iq:privacy");
sdm.addFeature("jabber.org/protocol/si");
sdm.removeFeature("http://jabber.org/protocol/ibb");
}
SmackConfiguration.DEBUG = true;
// FileTransfer
ProviderManager.addIQProvider("query","http://jabber.org/protocol/bytestreams",new BytestreamsProvider());
ProviderManager.addIQProvider("query",
"http://jabber.org/protocol/disco#items",new DiscoverItemsProvider());
ProviderManager.addIQProvider("si","http://jabber.org/protocol/si",new StreamInitiationProvider());
ProviderManager.addIQProvider("x","jabber:x:roster", new RosterPacketProvider());
fileTransferNegotiator=FileTransferNegotiator.getInstanceFor(main.login.connection);
fileTransferNegotiator.IBB_ONLY = false;
&#13;