【问题标题】:GCDASyncSocket SSL don't connectGCDASyncSocket SSL 不连接
【发布时间】:2012-11-25 21:23:27
【问题描述】:

我的套接字连接正常工作,但服务器已更新为 SSL。我称这种方法为:

[socket startTLS:nil];

但我仍然无法与服务器建立安全连接。我这样发起连接:

- (void) initNetworkCommunication {

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

    NSError *err = nil;
    if (![socket connectToHost:@"192.168.2.210" onPort:1333 viaInterface:@"" withTimeout:-1 error:&err]) // Asynchronous!
    {
            // If there was an error, it's likely something like "already connected" or "no delegate set"
        NSLog(@"I goofed: %@", err);
    }else
    {
        NSLog(@"Connecting...");
    }
    [socket readDataWithTimeout:-1 tag:1];

}

你能帮我解决这个问题吗?

【问题讨论】:

    标签: ios cocoa sockets ssl tcpclient


    【解决方案1】:

    我在进行 initNetworkCommunication 之后调用了 [socket startTLS:nil],但它应该在我们建立连接的那一刻,像这样:

    - (void) initNetworkCommunication {
    
        dispatch_queue_t mainQueue = dispatch_get_main_queue();
        socket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:mainQueue];
    
        NSError *err = nil;
        if (![socket connectToHost:@"192.168.2.210" onPort:1333 viaInterface:@"" withTimeout:-1 error:&err]) // Asynchronous!
        {
                // If there was an error, it's likely something like "already connected" or "no delegate set"
            NSLog(@"I goofed: %@", err);
        }else
        {
            [socket startTLS:nil];
            NSLog(@"Connecting...");
    
            }
            [socket readDataWithTimeout:-1 tag:1];
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-05
      相关资源
      最近更新 更多