基于XMPP的Smack4.16与OpenFire建立连接并实现实时监听、发送与接收消息
import org.jivesoftware.smack.*;
import org.jivesoftware.smack.chat.Chat;
import org.jivesoftware.smack.chat.ChatManager;
import org.jivesoftware.smack.chat.ChatManagerListener;
import org.jivesoftware.smack.chat.ChatMessageListener;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.sasl.javax.SASLDigestMD5Mechanism;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
import java.io.IOException;
public class ConnectionUtil extends Thread{
public static String jid = null;
public boolean connect(String username,String password,String serverName) {
boolean target=false;
//Smack连接的基本配置
XMPPTCPConnectionConfiguration.Builder config = XMPPTCPConnectionConfiguration.builder()
.setCompressionEnabled(false)
.setDebuggerEnabled(false)