At this stage of communication services, all kinds of standards have, so there will be unable to achieve interconnection, and XMPP (extensible Message and Presence Protocol) protocol, the realization of the entire timely Communication Service protocol interoperability. With this agreement, the use of any one organization or individual, even if the communication services, can be accessible to other users of the timely communication services to communicate. Google Talk, for example, launched in 2005, is an XMPP protocol-based instant messaging software. Let's talk a little bit about how to use XMPP easily
First, the construction of the environment, this article uses the OpenFire server |
1. Download the latest OpenFire for Mac version http://www.igniterealtime.org/downloads/index.jsp
2. Click the icon below to install the JDK and server
3. After starting, click the Open Admin Console button to automatically open the local Web configuration page in the browser http://localhost:9090/setup/index.jsp and then configure the server.
4. Set the language to Chinese
5. Set the server address to native
6. Set up the database
Before you perform this step, you need to do some preparatory work,
1 Create a database: CREATE database OpenFire;
2 Import the data table under OpenFire Resource folder resources/database: Source/usr/local/openfire/resources/database/openfire_mysql.sql
7. Feature Settings
8, set the OpenFire server administrator's account number and password
9, the installation is complete, click the button login
Login after the interface is as follows
10. Create user password According to the above operation
11, this time the preparation work basically completes
1, the XMPP all into the project
2. Importing dependent Packages
Because of the existence of a dynamic library, the following actions are required
Three, so far our XMPP successfully imported into the project, below we began to code to implement user login |
1, introduce the package inside the agent, and define the flow properties
2. Initialize and add agents
#pragma Mark initialization-(void) setupstream{ if (_stream==nil) { / /1 Initialize stream _stream=[[Xmppstream alloc] init]; // 2 adding Agents 0 )]; } }
3. Establish the connection
#pragmaMark establishes the link//Establish a connection- (void) connect{//1 Initialization[self setupstream]; //2 Setting the server address, user name, passwordNSString * username=@"[email protected]"; NSString* Hostname=@"jereh.local"; //3 Setting up Jid and hostsXmppjid * jid=[Xmppjid Jidwithstring:username]; [Self.stream Setmyjid:jid]; [Self.stream Sethostname:hostname]; //4 Start ConnectionNserror *error; [Self.stream connectwithtimeout:xmppstreamtimeoutnone Error:&ERROR]; if(Error) {NSLog (@"failed to send connection request"); }Else{NSLog (@"Send connection request succeeded"); } }
5, password authentication, through the proxy method to return results
#pragmaMark validates the identity request-(void) Xmppstreamdidconnect: (Xmppstream *) sender{NSLog (@"Link Successful"); //Send an authentication requestNSString * pwd=@"jereh123"; [Self.stream authenticatewithpassword:pwd error:nil];}#pragmaMark has the correct password-(void) Xmppstreamdidauthenticate: (Xmppstream *) sender{NSLog (@"Authentication Successful"); //Notify server on-line[self onLine];}#pragmaMark Password Error-(void) Xmppstream: (Xmppstream *) sender Didnotauthenticate: (Nsxmlelement *) error{NSLog (@"failed authentication");}
6. Start Connection
To learn more about the small partners, you can click to view the source code , run the test yourself.
Inquiries or technical exchanges, please join the official QQ Group: (452379712)
Jerry Education
Source:http://www.cnblogs.com/jerehedu/
This article is the copyright of Yantai Jerry Education Technology Co., Ltd. and the blog Park is shared, welcome reprint, but without the consent of the author must retain this paragraph statement, and in the article page obvious location to the original link, otherwise reserves the right to pursue legal responsibility.
Introduction to XMPP Usage--Login