2009-05-04 19 views
1

私は既存のサーバーアプリケーションのクライアントであるiPhoneアプリを持っています。NSHostは非常に長い時間がかかります

次のコードを使用して接続していますが、このコードは正常に動作しています。今日私はプロジェクトの作業を開始し、何か変わったことが起こっています。

「接続」をクリックすると、NSHostは解決してホストに接続するのに約30-45秒かかります。接続が確立されると、データ転送速度は正常かつ高速です。

私は同じサーバーに接続しているクライアントソフトウェア(PCアプリケーション)を持っており、すぐに接続が処理されます!

おそらく誰かが...被写体に

-(IBAction)tryConnection{ 
    [self showLogoffButtons]; 
    iPhone_PNPAppDelegate *mainDelegate = (iPhone_PNPAppDelegate *)[[UIApplication sharedApplication] delegate]; 
    settings=mainDelegate.settings; 
    [activityindicator startAnimating]; 
    sendState=0; 

    NSHost* host; 

    //30-45 second pause happens here (since I am using an IP Address) 
    host = [NSHost hostWithAddress:settings.masterLocation]; 
    //NSHost returns (eventually) with the correct connection. 

    if (!host) { 
     host = [NSHost hostWithName:settings.masterLocation]; 
    } 
    if(host) { 
     [NSStream getStreamsToHost:host port:[settings.masterPort intValue] inputStream:&iStream outputStream:&oStream] ; 
     if(nil != iStream && nil != oStream) { 
      [iStream retain]; 
      [oStream retain]; 
      [iStream setDelegate:self]; 
      [oStream setDelegate:self]; 
      [iStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; 
      [oStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; 
      [iStream open]; 
      [oStream open]; 
     }else{ 
      [self resetConnectionAndScreen]; 
      [email protected]"Connection Error! Please check connection settings."; 
     } 

    }else{ 
     [self resetConnectionAndScreen]; 
     [email protected]"Connection Error! Please check connection settings."; 
    } 
} 

//をいくつかの光を当てることができ、私も今、これらの警告を取得しています。** ... WTH! :)

  • 警告:いいえ '+ hostWithAddress:':一致するメソッドのシグネチャなし
  • 警告(メッセージ:この方法は、
  • 警告が見つかりませ '+ hostWithName:' メソッドは、
  • 警告が見つかりません:「NSStreamポート:InputStreamの:のOutputStream:+ getStreamsToHost 'に応答しないこと ''
+0

'NSHost'も' getStreamstoHostどちらを使用してネットワーク化する別の方法です... 'iPhone上に存在します – user102008

答えて

1

私は次のように私のコードを更新している、私の問題を解決した

ここ
-(IBAction)tryConnection{ 
    CFReadStreamRef readStream = NULL; 
    CFWriteStreamRef writeStream = NULL; 
    CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (CFStringRef)settings.masterLocation, [settings.masterPort intValue], &readStream, &writeStream); 
    if (readStream && writeStream) { 
     CFReadStreamSetProperty(readStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue); 
     CFWriteStreamSetProperty(writeStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue); 

     iStream = (NSInputStream *)readStream; 
     [iStream retain]; 
     [iStream setDelegate:self]; 
     [iStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; 
     [iStream open]; 

     oStream = (NSOutputStream *)writeStream; 
     [oStream retain]; 
     [oStream setDelegate:self]; 
     [oStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; 
     [oStream open];  
    } 
    if (readStream) CFRelease(readStream); 
    if (writeStream) CFRelease(writeStream); 
} 
関連する問題