这里用的smack 4.3.4,有一些改变要注意:
import org.jivesoftware.smack.AbstractXMPPConnection;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSession;
import java.net.InetAddress;
public class Main {
public static void main(String[] args) {
Main.init();
}
public static AbstractXMPPConnection init(){
AbstractXMPPConnection connection = null;
try {
System.out.println("正在登录。。。");
XMPPTCPConnectionConfiguration configuration = XMPPTCPConnectionConfiguration.builder()
.setHostAddress(InetAddress.getByName("127.0.0.1"))//代替setHost
.setXmppDomain("localhost")//主机名,setServercName已过时
.setUsernameAndPassword("admin","pass")//账号密码
.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)//安全验证方式,不设置的话似乎要安装证书之类的
.build();
connection=new XMPPTCPConnection(configuration);
connection.connect();
System.out.println("服务器连接成功!");
connection.login();
System.out.println("登录成功!");
}catch (Exception e){
System.out.println("登录失败!!!");
}
return connection;
}
}