2016-07-20 11 views
0

ローカルIP接続を確認する際に問題が発生しました。Objective-C:IP接続を確認してください

私はこのプロジェクトhttps://github.com/pbkhrv/SimpleSocketConnectionを使ってポートでIPをチェックしています。

私は1つのIP接続したい。この作品の罰金:

[[NetworkController sharedInstance] connect:@"192.168.1.100"]; 

をしかし、私はそのような多くの接続を確認したいとき:

for(int i=1; i<255; i++) { 
    NSString *ip = [NSString stringWithFormat:@"192.168.1.%d", i]; 
    [[NetworkController sharedInstance] connect:ip]; 
} 

任意のアイデアなぜこれが動作しませんか?

+0

では少しあいまいです。あなたは何を期待していますか?何が起こっていないのですか?彼らのエラーメッセージはありますか? –

+1

良い質問をするためのいくつかの詳細については、[こちら](http://stackoverflow.com/help/how-to-ask)をご覧ください。 –

+0

ipとの接続が存在するかどうかを確認するために、多くの接続をチェックしようとしています。 –

答えて

0
@interface ViewController() 
- (void)displayMessage:(NSString*)message; 
@end 


@implementation ViewController 

#pragma mark - Private methods 

- (void)displayMessage:(NSString*)message { 
    // These two came from UITextView+Utils.h 
    [textViewOutput appendTextAfterLinebreak:message]; 
    [textViewOutput scrollToBottom]; 
} 


#pragma mark - Public methods 

- (IBAction)connect:(id)sender { 

    for(int i=1; i<255; i++) { 
     NSString *ip = [NSString stringWithFormat:@"192.168.1.%d", i]; 
     [[NetworkController sharedInstance] connect:ip]; 
    } 


} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    // Enable input and show keyboard as soon as connection is established. 
    [NetworkController sharedInstance].connectionOpenedBlock = ^(NetworkController* connection){ 
    [textInput setUserInteractionEnabled:YES]; 
    [textInput becomeFirstResponder]; 

     NSLog(@"Connection opened"); 

    [self displayMessage:@">>> Connection opened <<<"]; 
    }; 

    // Disable input and hide keyboard when connection is closed. 
    [NetworkController sharedInstance].connectionClosedBlock = ^(NetworkController* connection){ 
    [textInput resignFirstResponder]; 
    [textInput setUserInteractionEnabled:NO]; 
    [self displayMessage:@">>> Connection closed <<<"]; 
    }; 

    // Display error message and do nothing if connection fails. 
    [NetworkController sharedInstance].connectionFailedBlock = ^(NetworkController* connection){ 
    [self displayMessage:@">>> Connection FAILED <<<"]; 
     NSLog(@"Connection failed"); 
    }; 

    // Append incoming message to the output text view. 
    [NetworkController sharedInstance].messageReceivedBlock = ^(NetworkController* connection, NSString* message){ 
    [self displayMessage:message]; 
    }; 
} 

これは "動かない"

関連する問題