connectionConfiguration.setExpiredCertificatesCheckEnabled(false);
connectionConfiguration.setDebuggerEnabled(true);
connectionConfiguration.setSASLAuthenticationEnabled(true);
connectionConfiguration.setSecurityMode(ConnectionConfiguration.SecurityMode.required);
XMPPConnection.DEBUG_ENABLED = true;
XMPPConnection connection = new XMPPConnection(connectionConfiguration);
connection.connect();
SASLAuthentication saslAuthentication = connection.getSASLAuthentication();
// saslAuthentication.authenticateAnonymously();
// saslAuthentication.authenticate("user1@vysper.org", "password1", "test");
// if (!saslAuthentication.isAuthenticated()) return;
connection.login(me + "@vysper.org", "password1");
connection.getRoster().setSubscriptionMode(Roster.SubscriptionMode.accept_all);
connection.addPacketListener(new IQListener(), new PacketFilter() {
public boolean accept(Packet packet) {
return packet instanceof IQ;
}
});
connection.addPacketListener(new PresenceListener(), new PacketFilter() {
public boolean accept(Packet packet) {
return packet instanceof Presence;
}
});
Chat chat = null;
if (to != null) {
Presence presence = new Presence(Presence.Type.subscribe);
presence.setFrom(connection.getUser());
String toEntity = to + "@vysper.org";
presence.setTo(toEntity);
connection.sendPacket(presence);
chat = connection.getChatManager().createChat(toEntity, new MessageListener() {
public void processMessage(Chat inchat, Message message) {
System.out.println("log received message: " + message.getBody());
}
});
}
connection.sendPacket(new Presence(Presence.Type.available, "pommes", 1, Presence.Mode.available));
Thread.sleep(1000);
// query server version
sendIQGetWithTimestamp(connection, new Version());
// query server time
sendIQGetWithTimestamp(connection, new Time());
/* while (to != null) {
// chat.sendMessage("Hello " + to + " at " + new Date());
try { Thread.sleep((new Random().nextInt(15)+1)*1000 ); } catch (InterruptedException e) { ; }
}*/
for (int i = 0; i < 10; i++) {
connection.sendPacket(new Presence(Presence.Type.available, "pommes", 1, Presence.Mode.available));
try {
Thread.sleep((new Random().nextInt(15) + 10) * 1000);
} catch (InterruptedException e) {
;
}
connection.sendPacket(new Presence(Presence.Type.available, "nickes", 1, Presence.Mode.away));
try {
Thread.sleep((new Random().nextInt(15) + 10) * 1000);
} catch (InterruptedException e) {
;
}
}
for (int i = 0; i < 2000; i++) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
;
}
}
connection.disconnect();
} catch (Throwable e) {
try {
Thread.sleep(120 * 1000);
} catch (InterruptedException ie) {
;