Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS:如何检查流连接是否超时_Ios_Stream_Timeout_Connection - Fatal编程技术网

iOS:如何检查流连接是否超时

iOS:如何检查流连接是否超时,ios,stream,timeout,connection,Ios,Stream,Timeout,Connection,在我的应用程序中,我使用 - (void)connectToServerUsingCFStream:(NSString *) urlStr portNo: (uint) portNo 此函数由另一个方法调用 - (void)connectToServer:(NSString *)serverName onPort:(int)portNo { [self connectToServerUsingCFStream:serverName portNo:portNo]; whil

在我的应用程序中,我使用

- (void)connectToServerUsingCFStream:(NSString *) urlStr portNo: (uint) portNo
此函数由另一个方法调用

- (void)connectToServer:(NSString *)serverName onPort:(int)portNo 
{

    [self connectToServerUsingCFStream:serverName portNo:portNo];

    while (!((iStream.streamStatus == 2) || (oStream.streamStatus == 2))) {

        continue; 
    }

    NSLog(@"Streams connected");

    [self sendLoginRequest];
}
现在我想知道是否有一个简单的可能性来检查我的连接请求是否超时(可能有特定的时间值?)。在我的while循环中有没有处理这个问题的方法,或者我应该使用不同的方法

提前感谢,,
Bautzi

我不知道您到底是如何实现连接的,但这里我有一些来自的连接代码,如代码注释所示:

/**
 * XMPPReconnect handles automatically reconnecting to the xmpp server due to accidental disconnections.
 * That is, a disconnection that is not the result of calling disconnect on the xmpp stream.
 * 
 * Accidental disconnections may happen for a variety of reasons.
 * The most common are general connectivity issues such as disconnection from a WiFi access point.
 * 
 * However, there are several of issues that occasionaly occur.
 * There are some routers on the market that disconnect TCP streams after a period of inactivity.
 * In addition to this, there have been iPhone revisions where the OS networking stack would pull the same crap.
 * These issue have been largely overcome due to the keepalive implementation in XMPPStream.
 * 
 * Regardless of how the disconnect happens, the XMPPReconnect class can help to automatically re-establish
 * the xmpp stream so as to have minimum impact on the user (and hopefully they don't even notice).
 * 
 * Once a stream has been opened and authenticated, this class will detect any accidental disconnections.
 * If one occurs, an attempt will be made to automatically reconnect after a short delay.
 * This delay is configurable via the reconnectDelay property.
 * At the same time the class will begin monitoring the network for reachability changes.
 * When the reachability of the xmpp host has changed, a reconnect may be tried again.
 * In addition to all this, a timer may optionally be used to attempt a reconnect periodically.
 * The timer is started if the initial reconnect fails.
 * This reconnect timer is fully configurable (may be enabled/disabled, and it's timeout may be changed).
 * 
 * In all cases, prior to attempting a reconnect,
 * this class will invoke the shouldAttemptAutoReconnect delegate method.
 * The delegate may use this opportunity to optionally decline the auto reconnect attempt.
 * 
 * Auto reconnect may be disabled at any time via the autoReconnect property.
 * 
 * Note that auto reconnect will only occur for a stream that has been opened and authenticated.
 * So it will do nothing, for example, if there is no internet connectivity when your application
 * first launches, and the xmpp stream is unable to connect to the host.
 * In cases such as this it may be desireable to start monitoring the network for reachability changes.
 * This way when internet connectivity is restored, one can immediately connect the xmpp stream.
 * This is possible via the manualStart method,
 * which will trigger the class into action just as if an accidental disconnect occurred.
**/

我不知道这是否满足您的要求。

我不知道您是如何实现连接的,但这里我有一些来自的连接代码,如代码注释所示:

/**
 * XMPPReconnect handles automatically reconnecting to the xmpp server due to accidental disconnections.
 * That is, a disconnection that is not the result of calling disconnect on the xmpp stream.
 * 
 * Accidental disconnections may happen for a variety of reasons.
 * The most common are general connectivity issues such as disconnection from a WiFi access point.
 * 
 * However, there are several of issues that occasionaly occur.
 * There are some routers on the market that disconnect TCP streams after a period of inactivity.
 * In addition to this, there have been iPhone revisions where the OS networking stack would pull the same crap.
 * These issue have been largely overcome due to the keepalive implementation in XMPPStream.
 * 
 * Regardless of how the disconnect happens, the XMPPReconnect class can help to automatically re-establish
 * the xmpp stream so as to have minimum impact on the user (and hopefully they don't even notice).
 * 
 * Once a stream has been opened and authenticated, this class will detect any accidental disconnections.
 * If one occurs, an attempt will be made to automatically reconnect after a short delay.
 * This delay is configurable via the reconnectDelay property.
 * At the same time the class will begin monitoring the network for reachability changes.
 * When the reachability of the xmpp host has changed, a reconnect may be tried again.
 * In addition to all this, a timer may optionally be used to attempt a reconnect periodically.
 * The timer is started if the initial reconnect fails.
 * This reconnect timer is fully configurable (may be enabled/disabled, and it's timeout may be changed).
 * 
 * In all cases, prior to attempting a reconnect,
 * this class will invoke the shouldAttemptAutoReconnect delegate method.
 * The delegate may use this opportunity to optionally decline the auto reconnect attempt.
 * 
 * Auto reconnect may be disabled at any time via the autoReconnect property.
 * 
 * Note that auto reconnect will only occur for a stream that has been opened and authenticated.
 * So it will do nothing, for example, if there is no internet connectivity when your application
 * first launches, and the xmpp stream is unable to connect to the host.
 * In cases such as this it may be desireable to start monitoring the network for reachability changes.
 * This way when internet connectivity is restored, one can immediately connect the xmpp stream.
 * This is possible via the manualStart method,
 * which will trigger the class into action just as if an accidental disconnect occurred.
**/

我不知道这是否满足您的要求。

也许可以检查
streamStatus
是否等于
NSStreamStatusError
(我假设您使用
NSStream
是因为
streamStatus
属性)?是的,我使用的是NSInputStream和NSOutputStream。重要的是,我必须等到连接建立后,才能继续我的其余代码。如何以正确的方式执行此操作?将委托设置为
NSStream
。当收到
nsstreamventopencompleted
时,继续您的代码。这意味着,您必须提取
下面的代码,同时
循环到另一个方法(例如
didOpenStreams
)。非常感谢。我将尝试以这种方式管理它可能会检查
streamStatus
是否等于
NSStreamStatusError
(我假设您使用
NSStream
是因为
streamStatus
属性)?是的,我使用的是NSInputStream和NSOutputStream。重要的是,我必须等到连接建立后,才能继续我的其余代码。如何以正确的方式执行此操作?将委托设置为
NSStream
。当收到
nsstreamventopencompleted
时,继续您的代码。这意味着,您必须提取
下面的代码,同时
循环到另一个方法(例如
didOpenStreams
)。非常感谢。我会尽量这样做