Hi all,
In order to test the reliability of the basic functionalities (connection, and packet listener) of my future IM client,
I’'ve done the following test a lot of times (25 times), and bad surprise on packet listener:
On 10 runs of XmppTest class test, I have, on average just 65% of CASE 1!
CASE 1:
//…log OK: presence packet seen…
: initialisation…
: connection created…
: packets listener initialized…
: user logged in…
instance created!
packet read:
//…
CASE 2:
//…log ko: presence packet not seen!..
: initialisation…
: connection created…
: packets listener initialized…
: user logged in…
instance created!
//…
=> sometimes packet is not read (or catched)! I cannot explain!!!
Any ideas? if some one could make the same test it would be great for my understanding…
Here, the code snippet of the basic XmppTest class test (which I could update with corrections when needed, to use it as example on this thread…)
package fr.elh.im.core;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.AndFilter;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Presence;
import fr.elh.im.utils.Constantes;
import fr.elh.im.xmpp.BasicPacketFilter;
/**
- @author me
*/
public class XmppTest {
private static final String LOGIN = “user1”;
private static final String PWD = “test”;
/**
- the xmpp connection
*/
public XMPPConnection connection;
/**
- the packet filter
*/
public PacketFilter packetFilter;
/**
- the packet listener
*/
public PacketListener packetListener = new PacketListener() {
public void processPacket(Packet packet) {
if(null != packet){
String xmlPacket = packet.toXML();
System.out.println(">packet read: " + xmlPacket);//dbg
}
}
};
/**
- default constructor
*/
public XmppTest() {
System.out.println(“[DBG]: initialisation…”);//dbg
createConnection();
System.out.println(“[DBG]: connection created…”);//dbg
initPacketsListener();
System.out.println(“[DBG]: packets listener initialized…”);//dbg
loginUserConnection(LOGIN,PWD);
System.out.println(“[DBG]: user logged in…”);//dbg
}
/**
-
Initialize the packet listener and filter packets on Presence criteria
-
(BasicPacketFilter() just accepts…)
*/
private void initPacketsListener(){
packetFilter = new AndFilter(new PacketTypeFilter(Presence.class), new BasicPacketFilter());
connection.addPacketListener(packetListener, packetFilter);
}
/**
- Create the Xmpp connection
*/
private void createConnection() {
try {
connection = new XMPPConnection(Constantes.jabberDomain.toString(),
5222);
} catch (XMPPException e) {
System.out
.println(“Error: could not create XMPP connection!”);// dbg
e.printStackTrace();
}
}
/**
-
@param l : login
-
@param p : pwd
*/
private void loginUserConnection(String l, String p) {
try {
connection.login(l, p);
} catch (XMPPException e) {
System.out.println("Error: authentification failed for: "
- l);
e.printStackTrace();
}
}
// main method for testings…
public static void main(String args) {
XmppTest test = new XmppTest();
if (null != test) {
System.out.println(“instance created!”);
} else {
System.out.println(“instance NOT created!”);
}
}
}
NB:
-
I never run 2 instances of XmppTest class at the same time during testings.
-
user 2 is always online during testings.
-
I’'m using smack 2.2.1 (seems to be the same with 2.2.0) and wilfire server 2.6.2 on win xp.
-
testings are done with Eclipse 3.2.0 and jdk1.5.
thx a lot…
Alex