Here is my code:
import java.io.*;
import java.text.*;
import java.util.*;
import org.jivesoftware.smack.*;
import org.jivesoftware.smack.packet.*;
import org.jivesoftware.smack.filter.*;
public class TestSmack extends Thread implements PacketListener
{
public void run()
{
while (true)
{
try
{
Thread.sleep(1000);
}
catch (Exception ex)
{
}
}
}
public void processPacket(Packet p_packet)
{
Message l_message = (Message)p_packet;
PrintLog("XML : " + l_message.toXML() + “\n”);
}
public void registerUser()
{
try
{
PrintLog(“Registering user.”);
XMPPConnection l_xmmpConnection = new XMPPConnection(“192.168.1.5”);
l_xmmpConnection.addPacketListener(this, new PacketTypeFilter(Message.class));
AccountManager l_accountManager = l_xmmpConnection.getAccountManager();
Map l_map = new HashMap();
l_map.put(“name”, “Tan Chen Yee”);
l_map.put(“email”, “tancy@win2000svrw”);
l_accountManager.createAccount(“tancy”, “tancy”, l_map);
PrintLog(“User is registered.”);
}
catch (Exception ex)
{
PrintLog("Exception in registerUser: " + ex.toString());
}
}
public void PrintLog(String p_strStatement)
{
Format l_fmtDate = new SimpleDateFormat("[hh:mm:ss a]");
System.out.println(l_fmtDate.format(new Date()) + " " + p_strStatement + “\n”);
}
public static void main(String args[])
{
TestSmack l_testSmack = new TestSmack();
l_testSmack.registerUser();
l_testSmack.start();
}
}
Here was the response:
E:\Jabber\API\Smack 2.1.0\code>java -classpath …/smack.jar;…/smackx.jar;./ TestSmack
Registering user.
User is registered.
As you can see, it took 21 seconds to register a user. How to shortern the time ?
Server and client PC is connected to a switch. There is not network delay.