I tried to test the max Clients of JM,so I made a class named XMPPClient which extends Thread,In the run method a connection is created and it communicated with some other user randomly;In another class I started some XMPPClient threads,but when the clients number up to 100(not exactly,but when the number is 30,it works),there is an exception:
XMPPError connecting to hy.test.net:5222.: (502)
caused by: java.net.ConnectException: Connection refused: connect
at org.jivesoftware.smack.XMPPConnection.chatDeamon(String toUser)
String newMessage = “test”;
Chat.setFilteredOnThreadID(false);
Chat newChat = conn.createChat(toUser);
try {
newChat.sendMessage(newMessage);
while (true) {
Message message = newChat.nextMessage();
this.sleep(1000);
String to = getAvailableClient();
newChat = conn.createChat(to);
newChat.sendMessage(newMessage);
}
}catch …
By the way,If I just create a connection as below,iIt can increase to more than 700 connections till there is no memory.
XMPPClient[] clients = new XMPPClient[num];
String user = “hy”;
for (int i = 0; i < num; i++) {
clients[i] = new XMPPClient();
clients[i].createConnection(“hy.test.net”, 5222);
clients[i].login(user, user, String.valueOf(i));
}