smack连接openfire

这里用的smimport 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; } } smack连接openfire

版权声明:玥玥 发表于 2021-06-14 20:20:38。
转载请注明:smack连接openfire | 女黑客导航