Dear All Experts,
I am writing this jabber bot that is supposed to be logged on all the time, and do something when it receives messages. Everything works fine in normal cases. So I try to test the exteme case, by writing another bot, logged into another account. and use a ‘‘for’’ loop to send about 1000 messages in a row to the jabber bot, to see if the jabber bot can received all of the messages.
some of the messages got dropped. the messages got dropped are not some random messages, but messages that come later. So I am guessing there’'s a buffer in the receiveListener.
I have attached the simple version of my jabber bot below.
PS : The number of messages increase SLIGHTLY when i decrease the sleep time.
import org.jivesoftware.smack.*;
import org.jivesoftware.smack.packet.*;
import org.jivesoftware.smack.filter.*;
import java.util.*;
import java.sql.*;
public class JabberBotTest extends Thread {
//JID of the php bot
private final static String PHP_BOT_JID="php@xxx.com";
private Connection dbConn;
private XMPPConnection jabberConn;
public int count = 0 ;
//debug flag
protected static boolean DEBUG=true;
/**
-
Constructor
-
Job : - connect to jabber, sql, and then update all of the status for ppl in the roster list
**/
public JabberBotTest() throws Exception{
this.jabberConn = new XMPPConnection(“xxx.com”);
this.jabberConn.login(???, ???);
}
public void createListeners ()
{
try{
final Chat phpbotChat = this.jabberConn.createChat(PHP_BOT_JID);
PacketListener packetListener = new PacketListener() {
public void processPacket(Packet packet) {
final Message message = (Message) packet;
count++;
System.out.println(count*" Message received from “*message.getFrom()+” : " + message.getBody());
}
};
jabberConn.addPacketListener(packetListener, new PacketTypeFilter(Message.class));
}catch(Exception ex){ex.printStackTrace();}
}
public static void main(String args[]){
JabberBotTest bot=null;
try{
bot = new JabberBotTest();
}catch(Exception ex){
ex.printStackTrace();
}
bot.createListeners();
try{
//bot.join();
while(true) {
sleep(500);
}
}
catch (InterruptedException ex){
ex.printStackTrace();
System.out.println(“Now turning off bot”);
}
}
}
Message was edited by:
Hans Paul