case NSStreamEventHasSpaceAvailable:
event = @"NSStreamEventHasSpaceAvailable";
if (theStream == oStream)
{
/**
//send data
uint8_t buffer[11] = "I send this";
int len;
len = [oStream write:buffer maxLength:sizeof(buffer)];
if (len > 0)
{
NSLog(@"Command send");
[oStream close];
}
**/
/**
NSMutableData *data1;
NSString *myString = @"string for data1";
const char *utfMyString = [myString UTF8String];
// initialize data1, data2, and secondBuffer...
NSMutableData* _data = [NSMutableData dataWithBytes:utfMyString length:strlen(utfMyString)+1];
uint8_t byteIndex;
uint8_t *readBytes = (uint8_t *)[_data mutableBytes];
readBytes += byteIndex; // instance variable to move pointer
int data_len = [_data length];
unsigned int len = ((data_len - byteIndex >= 1024) ?
1024 : (data_len-byteIndex));
uint8_t buf[len];
(void)memcpy(buf, readBytes, len);
len = [oStream write:(const uint8_t *)buf maxLength:len];
byteIndex += len;
**/
/**
NSData *data = UIImageJPEGRepresentation(drawImage.image, 90);
NSInteger x = [oStream write:[data bytes] maxLength:[data length]];
**/
NSString* test = @"Hello";
[test retain];
NSData *data = [test dataUsingEncoding: NSASCIIStringEncoding];
// Convert from host to network endianness
uint32_t length = (uint32_t)htonl([data length]);
// Don't forget to check the return value of 'write'
[oStream write:(uint8_t *)&length maxLength:4];
[oStream write:[data bytes] maxLength:length];
[oStream close];
}
break;