Environment preparation: 1. install the openfire server and configure related items. introduce smack * in the project *. the jar package source code is as follows: [java] package com. xjtu. jointframe. im. util; import java. util. arrayList; import java. util. collection; import java. util. iterator; import java. util. list; import org. jivesoftware. smack. chat; import org. jivesoftware. smack. connection; import org. jivesoftware. smack. connectionConfiguration; import org. jivesoftware. smack. messageListener; import org. jivesof Tware. smack. roster; import org. jivesoftware. smack. rosterEntry; import org. jivesoftware. smack. XMPPConnection; import org. jivesoftware. smack. XMPPException; import org. jivesoftware. smack. packet. message;/***** <p> * Description: example business class * </p> ** <p> * Copyright: Copyright (c) 2012 * </p> *** @ author dml @ 2013-2-21 * @ version 1.0 */www.2cto. compublic class IMServer {private static final String IP = "127.0.0.1"; private static final Integer DK = 5222; private static Roster roster;/*** get connection *** @ return Connection */public static connection getConnection () {ConnectionConfiguration config = new ConnectionConfiguration (IP, DK); Connection connection = new XMPPConnection (config); return connection ;} /*** send a notification message ** @ param username * @ param pass * @ param messgage * @ param groupName * @ th Rows XMPPException */public void SendBCMsg (String username, String pass, String messgage, String groupName) throws XMPPException {Connection con = IMServer. getConnection (); con. connect (); con. login (username, pass); Message m = new Message (); m. setBody (messgage); // sets the message. M. setTo (groupName + "@ broadcast. xjtu "); // [groupname] @ [serviceName]. [serverName] con. sendPacket (m);}/*** send instant message ** @ param username * @ param pass * @ param messgage * @ throws XMPPException */public void SendMsg (String username, string pass, String messgage) throws XMPPException {Connection con = IMServer. getConnection (); con. connect (); con. login (username, pass); Chat mychat = con. getChatManager (). createChat ("admin @ xjtu", // JID of the acceptor. JID is the new MessageListener () {@ Override public void processMessage (Chat chat, Message message) of the domain to be added) {String messageBody = message. getBody (); System. out. println ("received message:" + messageBody + "" + message. getFrom () ;}}); mychat. sendMessage (messgage); // send message con. disconnect (); // disconnect}/*** get friend List ** @ param username * @ param pass * @ return * @ throws XMPPException */public List <RosterEntry> getRosterList (String username, string pass) throws XMPPException {Connection con = IMServer. getConnection (); con. connect (); con. login (username, pass); Collection <RosterEntry> rosters = con. getRoster (). getEntries (); for (RosterEntry rosterEntry: rosters) {System. out. print ("name:" + rosterEntry. getName () + ", jid:" + rosterEntry. getUser (); // you can obtain the JID System. out. println ("");} return null;}/*** get the user list (including group information) ** @ param username * @ param pass * @ return * @ throws XMPPException */public List <RosterEntry> getRoster (String username, String pass) throws XMPPException {Connection con = IMServer. getConnection (); con. connect (); con. login (username, pass); roster = con. getRoster (); List <RosterEntry> EntriesList = new ArrayList <RosterEntry> (); Collection <RosterEntry> rosterEntry = roster. getEntries (); Iterator <RosterEntry> I = rosterEntry. iterator (); while (I. hasNext () {EntriesList. add (I. next ();} return EntriesList ;}}