Server and database are installed first
With the server, I'm using OpenFire, the database is MySQL.
Two links recommended here
Configure MySQL with MySQL Workbench
http://justsee.iteye.com/blog/1753467
Configuring the server OpenFire
Http://www.cnblogs.com/xiaodao/archive/2013/04/05/3000554.html
First configure the database and then configure the server.
All two open.
The next XMPP client, which is used to test the
I'm under the Adium.
Down here.
http://xmpp.org/xmpp-software/clients/
Then add the account in Adium, the server will be set up with OpenFire 127.0.0.1, Port 5222
Here OpenFire the server port inside, 5222 is the client connection server
After successful login, you can see that the user is online in OpenFire.
Then another client, I directly with the code, feel trouble did not do interface
Set Xmppstream
Then set the account, at least test, so directly in the Viewdidload wrote
Then is to verify the password, the following method is on-line, these are proxy methods, Remember to set Xmppstream agent
This is the way to receive information, I do not interface, directly print out the accepted information
This method is called if the validation fails.
At first I run the error that always returns XMPP validation failed
Later in OpenFire view username must be with server name
For example, my account is test123, set Jid username is [email protected]
Then run, no error, in OpenFire display already online
Then you can start chatting, the following is the first hair, the above is the previous chat record
Sent a text and a link
Then Xcode outputs
Instant Messaging is the simplest way to get out of the app and the OpenFire backstage will show the offline
Code
#import "ViewController.h"#import "XMPP.h"@interfaceViewcontroller () <XMPPStreamDelegate>@property (nonatomic,strong) Xmppstream*stream;@end@implementationViewcontroller-(Xmppstream *) stream{if(!_stream) {_stream=[[Xmppstream alloc] init]; [_stream adddelegate:self Delegatequeue:dispatch_get_current_queue ()]; } return_stream;}- (void) viewdidload {[Super viewdidload]; [Self.stream Setmyjid:[xmppjid jidwithstring:@"[email protected]"]]; [Self.stream sethostname:@"127.0.0.1"]; [Self.stream Sethostport:5222]; Nserror*error =Nil; [Self.stream connectwithtimeout:1.0ferror:&ERROR]; if(Error) {NSLog (@"connectwithtimeout:%@", error); }}- (void) Xmppstream: (Xmppstream *) sender Didreceivemessage: (Xmppmessage *) message{NSString*msg = [[Message elementsforname:@"Body"] Lastobject]; NSLog (@"%@", MSG); }- (void) Xmppstreamdidconnect: (Xmppstream *) sender{Nserror*error =Nil; [Self.stream Authenticatewithpassword:@"test123"error:&ERROR]; if(Error) {NSLog (@"Authenticatewithpassword:%@", error); }}- (void) Xmppstreamdidauthenticate: (Xmppstream *) sender{xmpppresence*presence =[xmpppresence presence]; [Self.stream sendelement:presence];}- (void) Xmppstream: (Xmppstream *) sender Didnotauthenticate: (Ddxmlelement *) error{NSLog (@"didnotauthenticate:%@", error);}
Easy implementation of XMPP Instant Messaging for iOS development