Objective-C
Objective-C
Resolve a Hostname to an IP Address
See more Socket/SSL/TLS Examples
Demonstrates Socket.DnsLookup, which resolves a hostname and returns one numeric IP address.
Background. A maxWaitMs of 0 waits indefinitely; a positive value bounds the wait. Resolved results may be served from Chilkat's process-wide DNS cache.
Chilkat Objective-C Downloads
#import <CkoSocket.h>
#import <NSString.h>
CkoSocket *socket = [[CkoSocket alloc] init];
// Resolve a hostname to a numeric IP address, waiting up to 5 seconds.
NSString *ipAddress = [socket DnsLookup: @"example.com" maxWaitMs: [NSNumber numberWithInt: 5000]];
if (socket.LastMethodSuccess == NO) {
NSLog(@"%@",socket.LastErrorText);
return;
}
NSLog(@"%@%@",@"Resolved IP address: ",ipAddress);