Objective-C
Objective-C
Poll a Socket for Available Data
See more Socket/SSL/TLS Examples
Demonstrates Socket.PollDataAvailable, which performs a nonblocking check for readable activity and returns whether data or another read-ready condition is present.
Background. This lets an application check for incoming data without blocking, for example in an event loop that services multiple tasks.
Chilkat Objective-C Downloads
#import <CkoSocket.h>
BOOL success = NO;
CkoSocket *socket = [[CkoSocket alloc] init];
// Connect to the server using TLS.
BOOL bTls = YES;
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;
}
// Perform a nonblocking check for readable data. Returns true when data or another read-ready
// condition is present, and false when nothing is immediately available.
BOOL bAvailable = [socket PollDataAvailable];
if (bAvailable != YES) {
NSLog(@"%@",@"No data is immediately available.");
}
else {
NSLog(@"%@",@"Data is available to read.");
}