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);
I’m getting: Wrote -1 bytes.
From the
write:maxLength:method documentation:The -1 return value means that an error occurred. You should use
[outStream streamError]to get an NSError object telling you what went wrong so you can try to fix it, or to get a description of the problem for the user.