Not surprisingly I'm a bit confused. I'm using AsyncSocket to manage my connection and using their echo server to bounce messages.
When I place a char on the network:
When I decompose the message from the send function I get 64 as the value
But when I receive the message and move the input stream to NSMutableData and decompose it (byteBuffer is the stream as NSMutableData)
I always get 104 as the first byte, where I am expecting the value of i from the send function.
Thanks
When I place a char on the network:
Code:
char i = 0;
i = 64;
[dataToSend appendData:[NSMutableData dataWithBytes:&i length:sizeof(char)]];
When I decompose the message from the send function I get 64 as the value
Code:
NSData *tstData = [NSData dataWithBytes:&i length:sizeof(char)];
unsigned char byteBuffer[sizeof(char)];
[tstData getBytes:byteBuffer];
NSLog(@"Output: %d", byteBuffer[0]);
But when I receive the message and move the input stream to NSMutableData and decompose it (byteBuffer is the stream as NSMutableData)
Code:
NSData *tstData = [NSData dataWithBytes:[byteBuffer subdataWithRange:NSMakeRange(0, [byteBuffer length])] length:[byteBuffer length]];
unsigned char myBytes[[tstData length]];
[tstData getBytes:myBytes];
for(int i = 0; i <[tstData length]; i++){
NSLog( @"\n\t pos: %d myBytes size %d value %d",i, [tstData length], myBytes[i]);
}
I always get 104 as the first byte, where I am expecting the value of i from the send function.
Thanks