Xmppframework for iOS client (5) add AutoPing

Source: Internet
Author: User

To monitor whether the server is valid, increase the heartbeat listener. With the XEP-0199 protocol, under the XMPPFrameWork framework, the XMPPAutoPing and XMPPPing classes can be used, because XMPPAutoPing has been combined into the XMPPPing class, so XMPPAutoPing is more convenient to use.

First, import the header file

# Import "XMPPAutoPing. h"

Declare member variables and attributes

@ Interface XMPPConnectManeger: NSObject <XMPPAutoPingDelegate>

{

XMPPAutoPing * _ xmppAutoPing;

}

@ Property (nonatomic, retain) XMPPAutoPing * xmppAutoPing;

In the implementation file

@ Synthesize xmppStream = _ xmppStream;

@ Synthesize xmppAutoPing = _ xmppAutoPing;

// Initialize and start ping

-(Void) autoPingProxyServer :( NSString *) strProxyServer

{

_ XmppAutoPing = [[XMPPAutoPingalloc] init];

[_ XmppAutoPingactivate: _ xmppStream];

[_ XmppAutoPingaddDelegate: selfdelegateQueue: dispatch_get_main_queue ()];

_ XmppAutoPing. respondsToQueries = YES;

_ XmppAutoPing. pingInterval = 2; // ping Interval

If (nil! = StrProxyServer)

{

_XmppAutoPing.tar getJID = [XMPPJID jidWithString: strProxyServer]; // set ping to the target server. If it is nil, It listens to the server currently connected to socketstream.

}

}

// Uninstall the listener

[_ XmppAutoPing deactivate];

[_ XmppAutoPing removeDelegate: self];

_ XmppAutoPing = nil;

// Ping the XMPPAutoPingDelegate delegate method:

-(Void) xmppAutoPingDidSendPing :( XMPPAutoPing *) sender

{

NSLog (@ "-(void) xmppAutoPingDidSendPing :( XMPPAutoPing *) sender ");

}

-(Void) xmppAutoPingDidReceivePong :( XMPPAutoPing *) sender

{

NSLog (@ "-(void) xmppAutoPingDidReceivePong :( XMPPAutoPing *) sender ");

}

 

-(Void) xmppAutoPingDidTimeout :( XMPPAutoPing *) sender

{

NSLog (@ "-(void) xmppAutoPingDidTimeout :( XMPPAutoPing *) sender ");

}

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.