然后下面代码,你懂的。
/** * 获取连接 * @return connection */ public static Connection getConnection() { String ip = "127.0.0.1"; Integer dk = 5222; ConnectionConfiguration config = new ConnectionConfiguration(ip, dk); Connection connection = new XMPPConnection(config); return connection; } public static void main(String[] args) { try { Connection con=Config.getConnection(); con.connect(); con.loginAnonymously();//匿名登录。 System.out.println("Authenticated = " + con.isAuthenticated() + " " + con.getUser()); Message m = new Message(); m.setBody("你好");//设置消息。 m.setTo("[email protected]");//[email protected] 说明一下只需要改后面的yyp-pc改成 相应的域名。 我这里是自己机器的名字。 con.sendPacket(m); } catch (XMPPException e) { // TODO Auto-generated catch block e.printStackTrace(); } }