I am working on an app that is using NSOutputStream and NSInputStream to try it out and see what I can make happen. I have modified This tutorial to allow me to use a old computer as a server! What I am having an issue with is i am trying to send a dictionary through a NSOutputStream and then receive it. unfortinily the server seems to be adding a byte of data so I can not successfully unarchive the data. Here is my code....
//sending the data
NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
[dic setObject:@"hi" forKey:@"hello"];
[dic setObject:@"whats up" forKey:@"huh"];
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:dic];//data is 365 bytes
NSLog(@"%@",data);
[self.outputStream write:data.bytes maxLength:data.length];
//receiving data from NSInputStream
case NSStreamEventHasBytesAvailable:
NSLog(@"has bytes available");
//_mutData = [NSMutableData new];
_mutData = [[NSMutableData alloc] init];
if (theStream == inputStream) {
uint8_t buffer[1024];
int len;
while ([inputStream hasBytesAvailable]) {
len = [inputStream read:buffer maxLength:sizeof(buffer)];
if (len > 0) {
[_mutData appendBytes:buffer length:len];
NSLog(@"Data: %@",_mutData);
NSLog(@"appended bytes");
}
}
}
break;
// trying to make the data into the dictionary
NSDictionary *dic = [NSKeyedUnarchiver unarchiveObjectWithData:_mutData];
NSLog(@"%@",dic);
Upon trying to unarchiveOjectWithData I get an error message of "* -[NSKeyedUnarchiver initForReadingWithData:]: incomprehensible archive (0x62, 0x70, 0x6c, 0x69, 0x73, 0x74, 0x30, 0x30)".
Upon looking at the data it appears that it is all the same except for the last two values of the data that comes in from the server it adds "0a" to the end of the data.
My question is what is going wrong why is this data being added somewhere in the server? Thanks for any help!