powered by Jive Software

How to send raw IQ packets using smack?


#1

Hi,

How can i send the packet below using smack??

> <iq type='set' id='remove1'>
>   <query xmlns='jabber:iq:roster'>
>     <item
>         jid='contact@example.org'
>         subscription='remove'/>
>   </query>
> </iq>

Regards,

Samba


#2

I would recommend that you do not use ‘raw’ stanzas to do this, but use the Roster object instead:

final Roster roster = connection.getRoster();
final RosterEntry entry = roster.getEntry("contact@example.org");
roster.removeEntry(entry);

Using the Roster is a less abstract and less error-prone way of doing this.

If you do want to send ‘raw’ stanzas, You can create an anonymous subclass of IQ, something along the lines of this:

final IQ iq = new IQ() {
  @Override
  public String getChildElementXML() {
    return "<query xmlns='jabber:iq:roster'><item jid='contact@example.org' subscription='remove'/></query>";
  }
};
iq.setType(IQ.Type.SET);
connection.sendPacket(iq);

As you see, the bottom example is a lot less clear. It’ll be harder to maintain code like this, and errors are more likely to sneak into your development process.


#3

Hi,

Here is the test sequence and the problem i am facing regarding subscription request.

  • Login to msn as user1@live.in and then logged into user2@live.in from smack code
  • Now adding user2@live.in from live messenger and smack code is receiving the subscription request and i am adding user1@live.in to my roster using roster.createEntry
  • I am also able to chat and able to see each other’s presence

Now my problem comes here:-

  • I am deleting user1@live.in from smack code using roster.RemoveEntry
  • But live messenger still shows user2@live.in as online
  • Then i deleted user2@live.in from live messenger
  • Now if i try to add user2@live.in again no subscription requeste is comming to presence listener in smack code. The contact is auto accepted and able to see the presence

Please guide me something and where i am thinking wrong?

Regards,

Samba


#4

Actually i tried ur code but i am unable to send message at my psi client

moreever 5 users are login in xmpp servers

but i am not receiving presence information of any one.

i am also tried smack debugger

it shows foloowing message

iq id=“d94HS-2” to=“test9@intime-rajesh/Smack” type=“result”>

as i should receive presence information of all 5 users


#5

If the users do not recieve presence information that the others generate, chances are that they are not subscribed to each-other. Could you use the Openfire admin panel to verify that all users are logged on, and have each-other on their respective rosters?


#6

yeah i am receiving messages now thanks a lot sir !!


#7

I am not able to receive iq packets when using packet listener and packet filter.

code

connection.addPacketListener(new MyPacketListener(),new PacketTypeFilter(IQ.class));

class MyPacketListener implements PacketListener{
public void processPacket(Packet packet){
System.out.println("Recv : " + packet.toXML());
}

This is what i get

Recv :


#8

Actually, you do recieve the packet, but Smack doesn’t know how to process the child element of your IQ stanza. Please refer to http://www.igniterealtime.org/builds/smack/docs/latest/documentation/providers.h tml


#9

i am trying to send a IQ packet/stanza but i dont find any constructor with no params for “org.igniterealtime.smack:smack-android-extensions:4.2.2” dependecy.

EDIT:

i replied to you 8 year later that’s funny


#10

I don’t understand. What are you trying to do and what has it to do with smack-android-extensions?