public static Packet sendAndWait(XMPPConnection c, Packet p, long timeout) throws XMPPException { PacketCollector pc = c.createPacketCollector(new PacketIDFilter(p.getPacketID())); c.sendPacket(p); final Packet result; if (timeout == 0) { result = pc.nextResult(); } else { result = pc.nextResult(timeout); } if (result == null) throw new XMPPException("Timeout occured waiting for response to id " + p.getPacketID()); XMPPError error = result.getError(); if (error != null) throw new XMPPException(error); return result; }
public CommandWithReplyImpl(XmppConnection con, Packet packet) { connection = con; packetID = packet.getPacketID(); // Setup a collector to receive the servers response collector = connection.createPacketCollector(new PacketIDFilter(packetID)); // Get the subscription id if applicable subscriptionID = null; subidPattern = Pattern.compile("subid=[\"']([\\w-]+?)[\"']"); // Set the results from the command to null result = null; if (connection.isConnected()) { try { connection.sendPacket(packet); } catch (IllegalStateException e) { // set result to an error result = new ArbitraryIQ(); result.setType(IQ.Type.ERROR); } } }
public boolean accept(Packet packet) { return packetID.equals(packet.getPacketID()); }