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 ");
}