Smack can be used for XMPP client development. After downloading smack and importing relevant jar files, you can start XMPP client development.
The following code connects the client to the tigase server and logs on to the server based on the user name and password.
Package XMPP; import Org. jivesoftware. smack. connectionconfiguration; import Org. jivesoftware. smack. connectionconfiguration. securitymode; import Org. jivesoftware. smack. xmppconnection; import Org. jivesoftware. smack. xmppexception;/*** XMPP client * @ author Hz * @ since 2014-09-01 * @ version 1.0.0 */public class client {public static xmppconnection xmpp_conn; public static connectionconfiguration xmpp_conf; // server IP Public static string xmpp_ip = new string ("10.3.93.213"); // server name public static string xmpp_host = new string ("tsung213 "); // server port public static int xmpp_port = 5222; // username and password public static string user = new string ("hz_12 "); public static string pass = new string ("123456"); public static void main (string [] ARGs) {conn () ;}// connection server public static void conn () {try {// configure the connection xmpp_conf = new connectionconfiguration (xmpp_ip, xmpp_port, xmpp_host); xmpp_conf.setreconnectionallowed (true); xmpp_conf.setsecuritymode (securitymode. disabled); Disabled (false); xmpp_conf.setcompressionenabled (false); // connect and log on to xmpp_conn = new xmppconnection (xmpp_conf) based on the user name and password; Enabled = true; xmpp_conn.connect (); xmpp_conn.login (user, pass); // obtain the relevant variable string TMP; TMP = xmpp_conn.getconnectionid (); system. out. println ("connectionid:" + TMP); TMP = xmpp_conn.gethost (); system. out. println ("Host:" + TMP); TMP = xmpp_conn.getservicename (); system. out. println ("servicename:" + TMP); TMP = xmpp_conn.getuser (); system. out. println ("User:" + TMP);} catch (xmppexception e) {system. out. println ("error:" + E. tostring ());}}}
Running result:
XMPP client development (1)