登錄代碼。登錄成功完成。Asmack文件發送錯誤503類型=用openfire取消
String host=AppContext.HOST;//myHost
String [] params={"a1","aa"}
int port=AppContext.PORT;//My Port 2777
String service=AppContext.SERVICE; //service = smack
ConnectionConfiguration connConfig = new ConnectionConfiguration(
host, port, service);
connConfig.setDebuggerEnabled(true);
Connection.DEBUG_ENABLED = true;
connConfig.setSASLAuthenticationEnabled(true);
XMPPConnection connection = new XMPPConnection(connConfig);
Log.e("XMPP LoginActivity Username ",params[0]+" pass "+params[1]);
try {
connection.connect();
connectionFlg=true;
Log.i("XMPP LoginActivity",
"Connected to " + connection.getHost());
} catch (XMPPException ex) {
Log.e("XMPP LoginActivity", "Failed to connect to "
+ connection.getHost());
Log.e("XMPP LoginActivity", ex.toString());
appContext.setConnection(null);
}
try {
if(connectionFlg)
{
connection.login(params[0], params[1]);
Log.i("XMPP LoginActivity",
"Logged in as " + connection.getUser());
Presence presence = new Presence(Presence.Type.available);
presence.setStatus("I’m available");
connection.sendPacket(presence);
loginFlg=true;
appContext.setConnection(connection);
}else
{
Log.e("XMPP LoginActivity", "Failed to connect to "
+ connection.getHost());
}
} catch (XMPPException ex) {
loginFlg=false; ;
Log.e("XMPP LoginActivity", "Failed to log in as "
+ params[0]);
Log.e("XMPP LoginActivity", ex.toString());
appContext.setConnection(null);
}
我的文件發送代碼是波紋管
public void sendFile(String sentTo) {
ProviderManager.getInstance().addIQProvider("query","http://jabber.org/protocol/bytestreams", new BytestreamsProvider());
ProviderManager.getInstance().addIQProvider("query","http://jabber.org/protocol/disco#items", new DiscoverItemsProvider());
ProviderManager.getInstance().addIQProvider("query","http://jabber.org/protocol/disco#info", new DiscoverInfoProvider());
FileTransferManager manager = new FileTransferManager(connection);
OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer(sentTo);
File file = new File(Environment.getExternalStorageDirectory()
.getPath() + "/user.json");
try {
transfer.sendFile(file, "test_file");
} catch (XMPPException e) {
e.printStackTrace();
}
while(!transfer.isDone()) {
if(transfer.getStatus().equals(Status.error)) {
System.out.println("ERROR!!! " + transfer.getError());
} else if (transfer.getStatus().equals(Status.cancelled)
|| transfer.getStatus().equals(Status.refused)) {
System.out.println("Cancelled!!! " + transfer.getError());
}
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if(transfer.getStatus().equals(Status.refused) || transfer.getStatus().equals(Status.error)
|| transfer.getStatus().equals(Status.cancelled)){
System.out.println("refused cancelled error " + transfer.getError());
} else {
System.out.println("Success");
}
}
在發送我得到這個下面兩個XML響應。請看一下。
1)
12:55:16 PM SENT (1092826504): <iq id="SU8c1-17" to="[email protected]" from="[email protected]/Smack" type="set"><si xmlns="http://jabber.org/protocol/si" id="jsi_2427513438410796738" profile="http://jabber.org/protocol/si/profile/file-transfer"><file xmlns="http://jabber.org/protocol/si/profile/file-transfer" name="user.json" size="379" ><desc>test_file</desc></file><feature xmlns="http://jabber.org/protocol/feature-neg"><x xmlns="jabber:x:data" type="form"><field var="stream-method" type="list-multi"><option><value>http://jabber.org/protocol/bytestreams</value></option><option><value>http://jabber.org/protocol/ibb</value></option></field></x></feature></si></iq>
2)
12:55:16 PM RCV (1092826504): <iq type="error" id="SU8c1-17" from="[email protected]" to="[email protected]/Smack"><si xmlns="http://jabber.org/protocol/si" id="jsi_2427513438410796738" profile="http://jabber.org/protocol/si/profile/file-transfer"><file xmlns="http://jabber.org/protocol/si/profile/file-transfer" name="user.json" size="379"><desc>test_file</desc></file><feature xmlns="http://jabber.org/protocol/feature-neg"><x xmlns="jabber:x:data" type="form"><field var="stream-method" type="list-multi"><option><value>http://jabber.org/protocol/bytestreams</value></option><option><value>http://jabber.org/protocol/ibb</value></option></field></x></feature></si><error code="503" type="cancel"><service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>
請朋友有所幫助。我已經嘗試了很多代碼片段。因爲三天,我很努力,只有:(
請澄清你的問題 - 應該發生什麼,發生了什麼? – Smutje
發送文件時發生503錯誤。看到第二個XML,它們是503錯誤代碼和服務不可用。這是主要問題。 :( – addy
由於他們的服務返回503,主要負責接收方,你不可能做任何事情來解決這個問題。 – Smutje