0
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.

lolwut
  • 3
  • 1
  • @anon: Dear me are you new to Objective-C? Worse than me? :D A NSInteger is not an object, so you can't use the object specifier in NSLog. ;) – lolwut Jul 22 '11 at 05:22
  • I was wrong for other reasons but you can do what I said. But, then again `NSInteger` would have to be a pointer too in what I said. – Dair Jul 22 '11 at 05:23

1 Answers1

3

From the write:maxLength: method documentation:

Return Value
The number of bytes actually written, or -1 if an error occurs. More information about the error can be obtained with streamError. If the receiver is a fixed-length stream and has reached its capacity, 0 is returned.

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.

ughoavgfhw
  • 39,734
  • 6
  • 101
  • 123