Hello,
I have a problem with Smack and Openfire as XMPP-Server. The bot I have programmed can send messaged, but the PacketListener does not receive any messages. I tried out some different XMPP-Servers like ejabberd and Prosody, and this problem only appears with Openfire.
Here is my code:
package xmppclient;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.SASLAuthentication;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
/**
*
-
@author Paul
/
public class Main {
XMPPConnection connection;
ConnectionConfiguration config;
/*-
@param args the command line arguments
*/
public static void main(String[] args) {
Main m = new Main();
m.start();
// TODO code application logic here
}
-
@param args the command line arguments
public void start() {
SASLAuthentication.supportSASLMechanism(“PLAIN”, 0);
SASLAuthentication.supportSASLMechanism(“DIGEST-MD5”, 0);
XMPPConnection.DEBUG_ENABLED = true;
config = new ConnectionConfiguration(“localhost”, 5222);
config.setSASLAuthenticationEnabled(true);
config.setSendPresence(false);
config.setRosterLoadedAtLogin(false);
config.setSecurityMode(ConnectionConfiguration.SecurityMode.enabled);
connection = new XMPPConnection(config);
try {
// Connect to the server
connection.connect();
connection.login("bot", "123456", "java");
Message message = new Message();
message.setTo(“paul@localhost”);
message.setSubject(“Testing”);
message.setBody(“This is a bot!”);
connection.sendPacket(message);
connection.addPacketListener(new PacketListener() {
public void processPacket(Packet packet) {
if(packet instanceof Message) {
Message msg = (Message)packet;
System.out.println(“XML:” + packet.toXML());
System.out.println(“Text:” + msg.getBody());
Message out = new Message();
out.setTo(msg.getFrom());
out.setBody("Message received!");
connection.sendPacket(out);
if(msg.getBody().equals(“exit”)) {
System.out.println("--------Connection closed!------");
connection.disconnect();
System.exit(0);
}
}
}
}, new PacketTypeFilter(Message.class));
} catch (XMPPException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
while(true) {
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
I also tried to figure out the differences between the received XML-Streams of the different XMPP-Server, but I haven’t found anything. They are nearly equal… perhaps you can find something?
I use the smack svn-trunk and Openfire 3.6.4.
With kind regards
PW
xmpp-received-streams.txt.zip (1398 Bytes)