hi,
I appreciate your reply and if you find any problems in understanding just let me know.
Environment : JiveMessenger Server and Smack API
Step1 : User1 connects to the server using the code,
XMPPConnection conn = new XMPPConnection(SERVER_NAME);
//Set the Default Subsciption mode to Manual
conn.getRoster().setDefaultSubscriptionMode(Roster.SUBSCRIPTION_MANUAL)
//Login to the Server
conn.login(userId,password);
//Check the authencity and send it accordingly
if(conn.isAuthenticated()&& conn.isConnected()){
return conn;
}
Step2: Add a Packet Collector to the XMPPConnection conn as obtained in Step1 with Packet filter for the Presence Type of messages,
PacketCollector packetCollector = conn.createPacketCollector(
new PacketFilter(){
public boolean accept(Packet packet) {
if(packet instanceof Presence){
Presence presence = (Presence)packet;
if(presence.getType() == Presence.Type.SUBSCRIBE ||
presence.getType() == Presence.Type.SUBSCRIBED ||
presence.getType() == Presence.Type.UNSUBSCRIBE ||
presence.getType() == Presence.Type.UNSUBSCRIBED
presence.getType() == Presence.Type.AVAILABLE
presence.getType() == Presence.Type.UNAVAILABLE
){
return true;
}
return false;
}
return false;
}
}
);
Step3 : Create a packet of type Presence send it to user2 as below ,
Presence presence = new Presence (Presence.Type.SUBSCRIBE);
presence.setTo(“user2” + SERVER_NAME);
presence.setProperty(“ProfileName” , “JUST ROCK”);
System.out.println("Packet Sent : " + presence.toXML());
conn.sendPacket(presence);
Step4 : Now connect user2 with the server as done in step 1 and 2 for user1 and then try to check the packets in the Packet collector (intialized in step2) of user2 as,
Packet packet = packetCollector.nextResult(1000);
if (packet instanceof Presence){
System.out.println("Packet Recieved : " + packet.toXML())
}
If you compare the packet sent and recieved there will be a node for the property in packet sent which will not be there in packet recieved .
-Neeraj