Updating presence using conn.sendPacket();

I have a method in my client that sends out a presence “alert” whenever the user changes the current presence. I have tried different ways including just iterating the roster and not creating a new Presence object each time in the iteration. The log print out of the XML seem correct but the SMACK debug shows that the presence updates are only going to two users. I am currently at a loss. Included is the current code and debug statements. Thanks in advance.

public void sendPresence(){

logger.info(“Start Send Presence!”);

//Presence myPres = ConfigFile.getDefaultPres();

//myPres.setFrom(MindIM.getUserJid());

//Iterator itr =myRoster.getEntries();

RosterEntry nextEntry = null;

RosterGroup nextGroup = null;

Iterator itr = myRoster.getGroups();

Iterator itrEntry = null;

Presence myPres = null;

while(itr.hasNext()){

myPres = new Presence(ConfigFile.getDefaultPres());

myPres.setFrom(MindIM.getUserJid());

nextGroup = (RosterGroup)itr.next();

itrEntry =nextGroup.getEntries();

while(itrEntry.hasNext()){

nextEntry= (RosterEntry)itrEntry.next();

logger.info(“Sending Presence to:”);

logger.info(nextEntry.getUser());

myPres.setTo(nextEntry.getUser());

conn.sendPacket(myPres);

logger.info(myPres.toXML());

}

}

itrEntry = null;

itrEntry =myRoster.getUnfiledEntries();

while(itrEntry.hasNext()){

nextEntry = (RosterEntry)itrEntry.next();

logger.info(“Sending Presence to:”);

logger.info(nextEntry.getUser());

myPres.setTo(nextEntry.getUser());

conn.sendPacket(myPres);

logger.info(myPres.toXML());

}

}

Log4j debug

142735 INFO mb.im.client.gui.MindIM - Start Send Presence!

142735 INFO mb.im.client.gui.MindIM - Sending Presence to:

142735 INFO mb.im.client.gui.MindIM - stesta@192.168.45.137

142735 INFO mb.im.client.gui.MindIM - On a Conference Calldnd

142735 INFO mb.im.client.gui.MindIM - Sending Presence to:

142735 INFO mb.im.client.gui.MindIM - talvarez@192.168.45.137

142735 INFO mb.im.client.gui.MindIM - On a Conference Calldnd

142735 INFO mb.im.client.gui.MindIM - Sending Presence to:

142735 INFO mb.im.client.gui.MindIM - rabbit8183@aimgateway.mindbridge.com

142735 INFO mb.im.client.gui.MindIM - On a Conference Calldnd

142735 INFO mb.im.client.gui.MindIM - Sending Presence to:

142745 INFO mb.im.client.gui.MindIM - klister@192.168.45.137

142745 INFO mb.im.client.gui.MindIM - On a Conference Calldnd

142745 INFO mb.im.client.gui.MindIM - Sending Presence to:

142745 INFO mb.im.client.gui.MindIM - jriviello@192.168.45.137

142745 INFO mb.im.client.gui.MindIM - On a Conference Calldnd

142745 INFO mb.im.client.gui.MindIM - Sending Presence to:

142745 INFO mb.im.client.gui.MindIM - richie165@aimgateway.mindbridge.com

142745 INFO mb.im.client.gui.MindIM - On a Conference Calldnd

142745 INFO mb.im.client.gui.MindIM - Sending Presence to:

142745 INFO mb.im.client.gui.MindIM - shay7@192.168.45.137

142745 INFO mb.im.client.gui.MindIM - On a Conference Calldnd

142745 INFO mb.im.client.gui.MindIM - Sending Presence to:

142745 INFO mb.im.client.gui.MindIM - jbollin@192.168.45.137

142755 INFO mb.im.client.gui.MindIM - On a Conference Calldnd

142755 INFO mb.im.client.gui.MindIM - Sending Presence to:

142755 INFO mb.im.client.gui.MindIM - bkeller@192.168.45.137

142755 INFO mb.im.client.gui.MindIM - On a Conference Calldnd

142755 INFO mb.im.client.gui.MindIM - Sending Presence to:

142755 INFO mb.im.client.gui.MindIM - dchristian@192.168.45.137

142755 INFO mb.im.client.gui.MindIM - On a Conference Calldnd

142755 INFO mb.im.client.gui.MindIM - Sending Presence to:

142755 INFO mb.im.client.gui.MindIM - richie165@192.168.45.137

142755 INFO mb.im.client.gui.MindIM - On a Conference Calldnd

142755 INFO mb.im.client.gui.MindIM - Sending Presence to:

142755 INFO mb.im.client.gui.MindIM - gordowyrm@aimgateway.mindbridge.com

142765 INFO mb.im.client.gui.MindIM - On a Conference Calldnd

142765 INFO mb.im.client.gui.MindIM - Sending Presence to:

142765 INFO mb.im.client.gui.MindIM - tkline@192.168.45.137

142765 INFO mb.im.client.gui.MindIM - On a Conference Calldnd

142765 INFO mb.im.client.gui.MindIM - Sending Presence to:

142765 INFO mb.im.client.gui.MindIM - mportner@192.168.45.137

142765 INFO mb.im.client.gui.MindIM - On a Conference Calldnd

142765 INFO mb.im.client.gui.MindIM - Sending Presence to:

142765 INFO mb.im.client.gui.MindIM - jmortland@192.168.45.137

142765 INFO mb.im.client.gui.MindIM - On a Conference Calldnd

142765 INFO mb.im.client.gui.MindIM - Sending Presence to:

142765 INFO mb.im.client.gui.MindIM - daveb@192.168.45.137

142765 INFO mb.im.client.gui.MindIM - On a Conference Calldnd

142775 INFO mb.im.client.gui.MindIM - Sending Presence to:

142775 INFO mb.im.client.gui.MindIM - twalters@192.168.45.137

142775 INFO mb.im.client.gui.MindIM - On a Conference Calldnd

142775 INFO mb.im.client.gui.MindIM - Sending Presence to:

142775 INFO mb.im.client.gui.MindIM - support@192.168.45.137

142775 INFO mb.im.client.gui.MindIM - On a Conference Calldnd

142775 INFO mb.im.client.gui.MindIM - Sending Presence to:

142775 INFO mb.im.client.gui.MindIM - gmarshal@192.168.45.137

142775 INFO mb.im.client.gui.MindIM - On a Conference Calldnd

142775 INFO mb.im.client.gui.MindIM - Sending Presence to:

142775 INFO mb.im.client.gui.MindIM - pjackson@192.168.45.137

142775 INFO mb.im.client.gui.MindIM - On a Conference Calldnd

142785 INFO mb.im.client.gui.MindIM - Sending Presence to:

142785 INFO mb.im.client.gui.MindIM - aimgateway.mindbridge.com/registered

142785 INFO mb.im.client.gui.MindIM - On a Conference Calldnd

142785 INFO mb.im.client.gui.MindIM - Sending Presence to:

142785 INFO mb.im.client.gui.MindIM - rhamburg@192.168.45.137

142785 INFO mb.im.client.gui.MindIM - On a Conference Calldnd

142785 INFO mb.im.client.gui.MindIM - Sending Presence to:

142785 INFO mb.im.client.gui.MindIM - pstalker@192.168.45.137

142785 INFO mb.im.client.gui.MindIM - On a Conference Calldnd

142785 INFO mb.im.client.gui.MindIM - Sending Presence to:

142785 INFO mb.im.client.gui.MindIM - jgavin@192.168.45.137

142785 INFO mb.im.client.gui.MindIM - On a Conference Calldnd

142785 INFO mb.im.client.gui.MindIM - Sending Presence to:

142795 INFO mb.im.client.gui.MindIM - ddunham@192.168.45.137

142795 INFO mb.im.client.gui.MindIM - On a Conference Calldnd

142795 INFO mb.im.client.gui.MindIM - Sending Presence to:

142795 INFO mb.im.client.gui.MindIM - jgibson@192.168.45.137

142795 INFO mb.im.client.gui.MindIM - On a Conference Calldnd

142795 INFO mb.im.client.gui.MindIM - Sending Presence to:

142795 INFO mb.im.client.gui.MindIM - rabbit8183%aimgateway.mindbridge.com@aimgateway.mindbridge.com

142795 INFO mb.im.client.gui.MindIM - On a Conference Calldnd

142795 INFO mb.im.client.gui.MindIM - Sending Presence to:

142795 INFO mb.im.client.gui.MindIM - dthomas@192.168.45.137

142795 INFO mb.im.client.gui.MindIM - On a Conference Calldnd

142795 INFO mb.im.client.gui.MindIM - Sending Presence to:

142805 INFO mb.im.client.gui.MindIM - ofields@192.168.45.137

142805 INFO mb.im.client.gui.MindIM - On a Conference Calldnd

142805 INFO mb.im.client.gui.MindIM - Sending Presence to:

142805 INFO mb.im.client.gui.MindIM - jgriffith@192.168.45.137

142805 INFO mb.im.client.gui.MindIM - On a Conference Calldnd

— smack sent –

presence id=“PN8EN-16” to="jbollin@192.168.45.137" from="mclovis@192.168.45.137/work">On a Conference Calldnd

On a Conference Calldnd

On a Conference Calldnd

On a Conference Calldnd

On a Conference Calldnd

On a Conference Calldnd

On a Conference Calldnd

On a Conference Calldnd

On a Conference Calldnd

On a Conference Calldnd

On a Conference Calldnd

On a Conference Calldnd

On a Conference Calldnd

On a Conference Calldnd

On a Conference Calldnd

On a Conference Calldnd

On a Conference Calldnd

On a Conference Calldnd

On a Conference Calldnd

On a Conference Calldnd

On a Conference Calldnd

On a Conference Calldnd

On a Conference Calldnd

On a Conference Calldnd

On a Conference Calldnd

On a Conference Calldnd

On a Conference Calldnd

On a Conference Calldnd

On a Conference Calldnd

On a Conference Calldnd

mclovis,

You are using the same Presence to send all the filed entries and another Presence to send all the unfiled entries. On the other side, Smack keeps the Packets to send in a collection and uses another process to actually send the packets. Therefore, it is quite possible that you are modifying the Presence instance before it is actually send.

To confirm my guess I’'d check if jbollin@192.168.45.137 is your last filed entry and also if jgriffith@192.168.45.137 is your last unfile entry. One other bad-consequence of using the same Presence instance is that you are sending many packets under the same PacketID.

FYI, you could simplify your code if you just get all the entries from the Roster instead of iterating on the Roster’'s groups and then iterating on the unfiled entries. Roster.getEntries() returns all the filed and unfiled entries.

One last question…why did you choose to send Presence packets?

Regards,

– Gato

mclovis,

One last suggestion, you should only send Presence packets to people that is online. To find out who’‘s online you could check if you have a Presence for each Roster’'s entry.

Regards,

– Gato

Not only that, but it’'s generally sort of strange to send presence packets to individual people at all. The normal thing to do is send presence packets to the server and then let the server notify all the appropriate people.

Regards,

Matt

Matt,

I appreciate the help. I started by sending the presence update to the server(stored in the variable domain). I then progressed to using Roster.getEntries(). I am currently using the following code(the original idea of just notifying the server. NOTE. The server is an earlier version of the Jabberd server. My test is other clients running on an interior Jabber network running many other clients. They do not see the change in presence. Do I need to say conn.sendPacket(presence.toXML())??

Thanks for all your help

Also thanks for your libraries

I will be open sourcing a Gui that using your libraries,JPIM and some other libraries shortly in an alpha stage, I had to add some method calls, and additional constructors to some of your classes. I used the Nov 23 build.

In addition here is the code that I am using

logger.info(“Start Send Presence!”);

Presence myPres = ConfigFile.getDefaultPres();

myPres.setFrom(MindIM.getUserJid());

myPres.setTo(domain);

conn.sendPacket(myPres);

logger.info(myPres.toXML());

Log4J output

47518 INFO mb.im.client.gui.MindIM - Start Send Presence!

47558 INFO mb.im.client.gui.MindIM - On a Conference Calldnd

Smack debug raw packets sent

On a Conference Calldnd

Matt,

I solved problem by not explicitly addressing Presence packet to server. Thanks again