1

私のアプリケーションでは、を使用してサーバーに接続します

- (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ループでこれを処理する方法はありますか、それとも別のものを使用する必要がありますか?

よろしくお願いします、バウツィ

4

1 に答える 1

1

接続を正確に実装する方法はわかりませんが、コードのコメントとして、XMPPFrameworkからの接続コードがいくつかあります。

/**
 * 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.
**/

このXMPPReconect クラスがあなたの要求を満たしているかどうかはわかりません。

于 2012-07-19T09:02:21.467 に答える