• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Errors occur when using NSOutputStream to transfer big files
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Errors occur when using NSOutputStream to transfer big files


  • Subject: Errors occur when using NSOutputStream to transfer big files
  • From: yiling wu <email@hidden>
  • Date: Wed, 29 Apr 2009 00:11:12 -0400

Hi, All

I'm trying to use the NSOutputStream class to transfer some audio file
through Bonjour service which is implemented on the iPhone simulator.I try
the following code with some small text files. It works well. But there are
always some error occurs() when I try to send the bigger ones -- some audio
file.

Any suggestions .... ? Thanks !


    NSArray *paths =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,
YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *sendFile = [documentsDirectory stringByAppendingPathComponent:
@"test1.caf"];
    NSData *myData = [[[NSData alloc] initWithContentsOfFile:sendFile]
autorelease];

    uint8_t *readBytes = (uint8_t *)[myData bytes];
    NSUInteger  byteIndex = 0;
    int myData_len = [myData length];

    while (_outStream && [_outStream hasSpaceAvailable]) {

            readBytes += byteIndex;
            unsigned int len = ((myData_len - byteIndex >= 1024) ? 1024 :
(myData_len-byteIndex));
            uint8_t buf[len];
            (void)memcpy(buf, readBytes, len);

            len = [_outStream write:(const uint8_t *)buf maxLength:len];
            byteIndex += len;
            }


Emma
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Errors occur when using NSOutputStream to transfer big files
      • From: Andrew Farmer <email@hidden>
  • Prev by Date: Re: errors building framework
  • Next by Date: Re: Errors occur when using NSOutputStream to transfer big files
  • Previous by thread: Re: File Reading Problems
  • Next by thread: Re: Errors occur when using NSOutputStream to transfer big files
  • Index(es):
    • Date
    • Thread