Question about NSFileHandle for socket use
Question about NSFileHandle for socket use
- Subject: Question about NSFileHandle for socket use
- From: "Brant Sears" <email@hidden>
- Date: Thu, 18 Aug 2005 17:41:52 -0700
- Thread-topic: Cocoa-dev Digest, Vol 2, Issue 1261
I have a question about using NSFileHandle with sockets. The code I have evolved from the Picture Sharing sample app. So, I have an application that is receiving data and then calling [NSFileHandle waitForDataInBackgroundAndNotify].
I noticed a problem when I was trying to move larger blocks of data across the socket using the [NSFileHandle writeData:] method. After writing all of the data, it closes the file handle. What I noticed is that 4096 bytes were received by the application that is receiving the data. The rest of the message is lost and the notification that there is data available is not posted again.
I then tried breaking the data being written in 4000 byte chunks, and then one final writeData: call for the rest of the data. What I found was that the receiving application had a notification where it received 4000 bytes. A second notification was received that had 4096 bytes and the remainder was lost.
Next, I tried putting a .2 second delay after each write data call (except the last one) by calling [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.2]]; This resulted in the receiving application receiving all of the data. Woo hoo.
Then it occurred to me that while this works fine on my super fast Macintosh G4 system, it might not work so great when I am communicating with a different device that might be slower or have less memory - even an older Mac. So, here's my question. Is there a good way for the sender to know how slow it should write the data to the NSFileHandle so that it doesn't go too fast for a given receiver?
Thanks.
Brant Sears
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden