NSDictionary *bundle = [NSDictionary dictionaryWithObjectsAndKeys:message,@"message", toUserName, @"receiver",fromUserName, @"sender", nil];
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:bundle];
NSOutputStream *outStream;
[toUser getInputStream:nil outputStream:&outStream];
[outStream open];
NSInteger bytes = [outStream write:[data bytes] maxLength: [data length]];
[outStream close];
success = YES;
NSLog(@"Wrote %ld bytes", bytes);
我得到:Wrote -1 bytes
。