(Objective-C) Send Bytes on a Socket Connection
Demonstrates how to send a mixture of binary (non-text) and text bytes on a socket connection.
#import <CkoSocket.h>
#import <CkoBinData.h>
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkoSocket *socket = [[CkoSocket alloc] init];
// Connect to some host:port
BOOL ssl = NO;
int maxWaitMillisec = 20000;
int port = 5555;
BOOL success = [socket Connect: @"test.com" port: [NSNumber numberWithInt: port] ssl: ssl maxWaitMs: [NSNumber numberWithInt: maxWaitMillisec]];
if (success != YES) {
NSLog(@"%@",socket.LastErrorText);
return;
}
// We wish to send a 0x00 byte followed by the us-ascii string "10800"
CkoBinData *bd = [[CkoBinData alloc] init];
[bd AppendByte: [NSNumber numberWithInt: 0]];
[bd AppendString: @"10800" charset: @"utf-8"];
// Send the entire contents of bd.
success = [socket SendBd: bd offset: 0 numBytes: 0];
if (success != YES) {
NSLog(@"%@",socket.LastErrorText);
return;
}
|