Xcode GCDAsyncSocket telnet连接

时间:2012-03-27 10:35:43

标签: ios xcode telnet gcdasyncsocket

我无法开始使用GCDAsyncSocket来使用telnet连接。 当我通过终端连接时,我得到一些文字,它要求我登录。 使用GCDAsyncSocket,我可以获得连接,但无法从中获取任何文本。

- (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"%s",__FUNCTION__);

    socket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];

    NSError *err = nil;
    if (![socket connectToHost:@"192.168.1.1" onPort:23 error:&err])
    {
        // If there was an error, it's likely something like "already connected" or "no delegate set"
        NSLog(@"I goofed: %@", err);
    }
    [socket readDataWithTimeout:5 tag:1];
}

- (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port {
    NSLog(@"Cool, I'm connected! That was easy.");

}

- (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag {
    NSLog(@"%s",__FUNCTION__);
    NSString *responce = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

    NSLog(@"responce=%@",responce);
}

数据以fffd01ff fd1ffffb 01fffb03

响应

响应始终为空。

0 个答案:

没有答案