XMPP client development (1), xmpp client development

Source: Internet
Author: User

XMPP client development (1), xmpp client development

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:


Teaches iphone Development about xmpp protocol for chat clients

It doesn't matter if you reply to yueyueqiu's post platform, because you use http and other protocols for communication, so you only need to communicate according to your own protocol.
 
XMPP client open-source development with NET should not be developed first

. Net open source is hard to find, good is harder to find, it is also junk to find

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.