Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 9th, 2012  |  syntax: None  |  size: 1.30 KB  |  hits: 157  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to get NSOutputStream to send or flush packets immediately
  2. if( [stream hasSpaceAvailable] )
  3. {
  4.    NSLog( @"Space avail" );
  5. }
  6. else {
  7.     NSLog(@"No space");
  8. }
  9. while( [stream hasSpaceAvailable] && ( [_outputBuffer length] > 0 ) )
  10. {
  11.     /* write as many bytes as possible */
  12.     NSInteger written = [stream write:[_outputBuffer bytes] maxLength:[_outputBuffer length]];
  13.     NSLog( @"wrote %i out of %i bytes to the stream", written, [_outputBuffer length] );
  14. if( written == -1 )
  15.     {
  16.         /* error, bad */
  17.         Log( @"Error writing bytes" );
  18.         break;
  19.     }
  20.     else if( written > 0 )
  21.     {
  22.         /* remove the bytes from the buffer that were written */
  23.         Log( @"erasing %i bytes", written );
  24.         [_outputBuffer replaceBytesInRange:NSMakeRange( 0, written ) withBytes:nil length:0 ];
  25.     }
  26. }
  27.        
  28. immediate pack buffer-> 040040008
  29. Space avail
  30. wrote 10 out of 10 bytes to the stream
  31. immediate pack buffer-> 040010005
  32. No space
  33. immediate pack buffer-> 030040007
  34. No space
  35. wrote 20 out of 20 bytes to the stream
  36. immediate pack buffer-> 030010004
  37. No space
  38. immediate pack buffer-> 040000004
  39. Space avail
  40. wrote 20 out of 20 bytes to the stream
  41. immediate pack buffer-> 030000003
  42. Space avail
  43. wrote 10 out of 10 bytes to the stream
  44. immediate pack buffer-> 040040008
  45. Space avail
  46. wrote 10 out of 10 bytes to the stream