Objective-C
Objective-C
Receive Bytes up to a Delimiter into a BinData
See more Socket/SSL/TLS Examples
Demonstrates Socket.ReceiveUntilByteBd, which reads bytes until a delimiter byte is encountered and appends all bytes up to and including the delimiter to a BinData.
Background. The delimiter is a raw byte value from 0 through 255. This is useful for framing schemes that terminate each message with a known delimiter byte.
Chilkat Objective-C Downloads
#import <CkoSocket.h>
#import <CkoBinData.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;
}
// Read bytes until the delimiter byte is encountered, appending all bytes up to and including the
// delimiter to a BinData. The delimiter is a raw byte value from 0 through 255 (here the linefeed
// byte, decimal 10).
CkoBinData *bd = [[CkoBinData alloc] init];
success = [socket ReceiveUntilByteBd: [NSNumber numberWithInt: 10] bd: bd];
if (success == NO) {
NSLog(@"%@",socket.LastErrorText);
return;
}
NSLog(@"%@%d%@",@"Received ",[bd.NumBytes intValue],@" bytes (including the delimiter).");