本文整理匯總了Java中org.jivesoftware.smack.packet.IQ.getType方法的典型用法代碼示例。如果您正苦於以下問題:Java IQ.getType方法的具體用法?Java IQ.getType怎麽用?Java IQ.getType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jivesoftware.smack.packet.IQ
的用法示例。
在下文中一共展示了IQ.getType方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: regist
import org.jivesoftware.smack.packet.IQ; //導入方法依賴的package包/類
/**
* 注冊用戶
* @param xmppConnection
* @param userName
* @param password
* @return 1、注冊成功 0、服務器沒有返回結果2、這個賬號已經存在3、注冊失敗
*/
public static int regist(XMPPConnection xmppConnection, String userName, String password) {
Registration registration = new Registration();
registration.setType(IQ.Type.SET);
registration.setTo(xmppConnection.getServiceName());
registration.setUsername(userName);
registration.setPassword(password);
// 這邊addAttribute不能為空,否則出錯。所以做個標誌是android手機創建的吧!!!!!
registration.addAttribute("android", "fhr");
PacketFilter filter = new AndFilter(new PacketIDFilter(registration.getPacketID()), new PacketTypeFilter(IQ.class));
PacketCollector collector = xmppConnection.createPacketCollector(filter);
xmppConnection.sendPacket(registration);
IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results停止請求results(是否成功的結果)
collector.cancel();
if (result == null) {
Log.e("regist", "No response from server.");
return 0;
} else if (result.getType() == IQ.Type.RESULT) {
Log.v("regist", "regist success.");
return 1;
} else {
if (result.getError().toString().equalsIgnoreCase("conflict(409)")) {
Log.e("regist", "IQ.Type.ERROR: " + result.getError().toString());
return 2;
} else {
Log.e("regist", "IQ.Type.ERROR: " + result.getError().toString());
return 3;
}
}
}
示例2: register
import org.jivesoftware.smack.packet.IQ; //導入方法依賴的package包/類
/**
* 注冊
*
* @param account
* 注冊帳號
* @param password
* 注冊密碼
* @return 1、注冊成功 0、服務器沒有返回結果2、這個賬號已經存在3、注冊失敗
*/
public static int register(XMPPConnection mXMPPConnection,String account, String password) {
Registration reg = new Registration();
reg.setType(IQ.Type.SET);
reg.setTo(mXMPPConnection.getServiceName());
// 注意這裏createAccount注冊時,參數是UserName,不是jid,是"@"前麵的部分。
reg.setUsername(account);
reg.setPassword(password);
// 這邊addAttribute不能為空,否則出錯。所以做個標誌是android手機創建的吧!!!!!
reg.addAttribute("android", "geolo_createUser_android");
PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class));
PacketCollector collector =mXMPPConnection.createPacketCollector(filter);
mXMPPConnection.sendPacket(reg);
IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results停止請求results(是否成功的結果)
collector.cancel();
if (result == null) {
return 0;
} else if (result.getType() == IQ.Type.RESULT) {
return 1;
} else {
if (result.getError().toString().equalsIgnoreCase("conflict(409)")) {
return 2;
} else {
return 3;
}
}
}
示例3: testInvalidNamespace
import org.jivesoftware.smack.packet.IQ; //導入方法依賴的package包/類
/**
* Check that the server responds a 503 error code when the client sends an IQ stanza(/packet) with an
* invalid namespace.
*/
public void testInvalidNamespace() {
IQ iq = new IQ() {
public String getChildElementXML() {
StringBuilder buf = new StringBuilder();
buf.append("<query xmlns=\"jabber:iq:anything\">");
buf.append("</query>");
return buf.toString();
}
};
PacketFilter filter = new AndFilter(new PacketIDFilter(iq.getStanzaId()),
new StanzaTypeFilter(IQ.class));
PacketCollector collector = getConnection(0).createPacketCollector(filter);
// Send the iq packet with an invalid namespace
getConnection(0).sendStanza(iq);
IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
collector.cancel();
if (result == null) {
fail("No response from server");
}
else if (result.getType() != IQ.Type.error) {
fail("The server didn't reply with an error packet");
}
else {
assertEquals("Server answered an incorrect error code", 503, result.getError().getCode());
}
}
示例4: acceptSpecific
import org.jivesoftware.smack.packet.IQ; //導入方法依賴的package包/類
@Override
protected boolean acceptSpecific(IQ iq) {
return iq.getType() == type;
}
示例5: testParseIQSimple
import org.jivesoftware.smack.packet.IQ; //導入方法依賴的package包/類
/**
* Test for parsing a Jingle
*/
public void testParseIQSimple() {
// Create a dummy packet for testing...
IQfake iqSent = new IQfake (
" <jingle xmlns='urn:xmpp:tmp:jingle'" +
" initiator=\"[email protected]\"" +
" responder=\"[email protected]\"" +
" action=\"transport-info\" sid=\"\">" +
" <transport xmlns='urn:xmpp:tmp:jingle:transports:ice-udp'>" +
" <candidate generation=\"1\"" +
" ip=\"192.168.1.1\"" +
" password=\"secret\"" +
" port=\"8080\"" +
" username=\"username\"" +
" preference=\"1\"/>" +
" </transport>" +
"</jingle>");
iqSent.setTo(getFullJID(0));
iqSent.setFrom(getFullJID(0));
iqSent.setType(IQ.Type.get);
// Create a filter and a collector...
PacketFilter filter = new StanzaTypeFilter(IQ.class);
PacketCollector collector = getConnection(0).createPacketCollector(filter);
System.out.println("Testing if a Jingle IQ can be sent and received...");
// Send the iq packet with an invalid namespace
getConnection(0).sendStanza(iqSent);
// Receive the packet
IQ iqReceived = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
collector.cancel();
if (iqReceived == null) {
fail("No response from server");
}
else if (iqReceived.getType() == IQ.Type.error) {
fail("The server did reply with an error packet: " + iqReceived.getError().getCode());
}
else {
assertTrue(iqReceived instanceof Jingle);
Jingle jin = (Jingle) iqReceived;
System.out.println("Sent: " + iqSent.toXML());
System.out.println("Received: " + jin.toXML());
}
}