首先打开openfire管理界面,用管理员进去 ,到里面找到插件,点击有效插件.找到Broadcast 这个插件,安装好之后。
然后下面代码,你懂的。
然后下面代码,你懂的。
/**
* 获取连接
* @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("all@broadcast.yyp-pc");//all@broadcast.yyp-pc 说明一下只需要改后面的yyp-pc改成 相应的域名。 我这里是自己机器的名字。
con.sendPacket(m);
} catch (XMPPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}