Objective-C
Objective-C
Upgrade a Plain TCP Connection to TLS
See more Socket/SSL/TLS Examples
Demonstrates Socket.ConvertToSsl, which upgrades an already-connected plain TCP socket to TLS by performing a client-side TLS handshake over the existing connection.
Background. This supports STARTTLS-style upgrades, where a protocol begins in plaintext and switches to TLS at a defined point. Perform the protocol-specific negotiation first, then call ConvertToSsl.
Chilkat Objective-C Downloads
#import <CkoSocket.h>
BOOL success = NO;
CkoSocket *socket = [[CkoSocket alloc] init];
// Connect as plain TCP (no TLS yet).
BOOL bTls = NO;
int maxWaitMs = 5000;
success = [socket Connect: @"example.com" port: [NSNumber numberWithInt: 5000] ssl: bTls maxWaitMs: [NSNumber numberWithInt: maxWaitMs]];
if (success == NO) {
NSLog(@"%@",socket.LastErrorText);
return;
}
// At the point where the application protocol permits a STARTTLS-style upgrade, perform any required
// negotiation, then upgrade the existing connection to TLS with a client-side handshake.
success = [socket ConvertToSsl];
if (success == NO) {
NSLog(@"%@",socket.LastErrorText);
return;
}
NSLog(@"%@",@"Connection upgraded to TLS.");