Objective-C
Objective-C
Send a 32-bit Integer over a Socket
See more Socket/SSL/TLS Examples
Demonstrates Socket.SendInt32, which sends a value as a four-byte signed integer in the selected byte order.
Background. Fixed-size integers and length prefixes are common building blocks for application-defined binary protocols. Byte order is selectable, with big-endian being network byte order.
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;
}
// Send the value as a four-byte signed integer. Use true for network byte order (big-endian) or
// false for little-endian.
BOOL bBigEndian = YES;
success = [socket SendInt32: [NSNumber numberWithInt: 1000000] bigEndian: bBigEndian];
if (success == NO) {
NSLog(@"%@",socket.LastErrorText);
return;
}
NSLog(@"%@",@"32-bit integer sent.");