aSmack4.0 Tour (i) Configuration introduction registration

Source: Internet
Author: User

aSmack4.0 Tour (i) Configure the registration chapter
First, what is smack?Smack is an open source, easy-to-use XMPP (jabber) client class library. The Smack API, a Java xmpp Client Library, is also developed by Jive Software. Advantages: Simple programming. Disadvantage: The API is not designed for a large number of concurrent users, each customer wants 1 threads, occupies a large resource, 1 machines can only simulate a limited (thousands of) customer. Smack is a Java-written XMPP client code base, which is the core of spark. Smack Advantages 1: Smack is a simple, powerful class library. Sending a message to a user requires only three lines of code to complete xmppconnection connection = new Xmpptcpconnection ("jabber.org"), Connection.login ("Mtucker", " Password "), Connection.createchat (" [email protected] "). SendMessage (" howdy! "); 2: You will not be forced to encode at the packet level like any other class library. It provides a more intelligent analogy like chat, which can make your job more efficient. 3: Do not need you to be familiar with XMPP XML format, even XML format. 4: Easy to implement machine-machine dialogue. Open source software under the 5:apace license. You can use it for your commercial or non-commercial processes. Okay, no more nonsense, let's get to the chase. After aSmack4.0 and smack basic difference is not so big, now say aSmack4.0 later version of the configuration and usefirst, we go to the official website to download the required jar Package if required source code is also provided by the officialhttp://asmack.freakempire.de/

Of course, don't forget to read the official version update instructions and the Readme before you start, or you'll be in big trouble.
4.0 after the change slightly larger point of use before you need to import two packages I use Asmack-android-8-4.0.5.jar and Dnsjava-2.1.3.jar don't forget Dnsjava.jar or smackandroid.init () It's going to go wrong!
Okay, let's start with our registration.
1. Smcakandroid,init (Getapplicationcontext ()); initialize.2, Configuration Connectionconfiguration
Configuration = new Connectionconfiguration (Config.getxmpphost (), Config.getxmppport (), Config.getxmppservernanme () );
Config.getxmpphost ()  openfir server address     config.getxmppport () port number (5222) Config.getxmppservernanme () the name is arbitrary. Android defaults to Smack

3, Configuration.setsecuritymode (securitymode.disabled); Set to Disabled otherwise authentication fails.4, connection = new Xmpptcpconnection (configuration); Good configuration is complete, the following is the beginning of the registration is directly affixed to the code

/** * Registration * * @param account * Registration * @param password * registration password */public int regist (String accounts, Str ing password) {try {xmppconnection connection = Xmppconnectionmanager.getinstance (). getconnection (); Connection.connect (); Registration REG = new registration (); Reg.settype (IQ. Type.set); Reg.setto (Connection.getservicename ()); map<string, string> map = new hashmap<string, string> (), Map.put ("username", account), Map.put ("Password", password); reg.setattributes (map); Packetfilter filter = new Andfilter (New Packetidfilter (Reg.getpacketid ()), New Packettypefilter (Iq.class)); Packetcollector collector = Xmppconnectionmanager.getinstance (). getconnection (). Createpacketcollector (filter); Connection.sendpacket (reg); IQ result = (IQ) Collector.nextresult (Smackconfiguration.getdefaultpacketreplytimeout () ); System.out.println ("-----------------result--------------------" + result); Collector.cancel ();// Stop request results (successful result)} catch (Exception e) {e.printstacktrace (); return ConstaNt. Login_error;} return constant.login_seccess;}
Precautions:
1. Note that registration is required for asynchronous operation or connection exception2, Asmack to ADT requirements is very high, preferably 23 and above, otherwise there are all kinds of wonderful mistakes
Well, it's here today, and I hope we can help.
Reprint Please specify source: http://blog.csdn.net/hellohhj/article/details/41074803





aSmack4.0 Tour (i) Configuration introduction registration

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.