Re: NSInputStream created from NSData - expected it to close at end of data, did not happen
Re: NSInputStream created from NSData - expected it to close at end of data, did not happen
- Subject: Re: NSInputStream created from NSData - expected it to close at end of data, did not happen
- From: Jens Alfke <email@hidden>
- Date: Fri, 10 Jun 2011 12:19:52 -0700
On Jun 10, 2011, at 11:39 AM, email@hidden wrote:
> 1. There an NSStream event "NSStreamEventEndEncountered". I would have expected to be sent this event when the Stream created from a piece of data reaches the end of that data. But okay, you said that one has to close the stream oneself. So I did that when the data input stream ![stream hasBytesAvailable] after having had bytes available. I then close the stream.
Those two things are not the same. That may be causing your trouble.
The hasBytesAvailable property tells you whether there is data available to read *right now*. It will return false if you’ve read all the bytes that have arrived, and no more have arrived yet.
NSStreamEventEndEncountered is posted when the EOF is reached. For a socket, that means that the other peer closed the connection.
Have you looked at the CocoaEcho sample code? It demonstrates how to do a simple TCP client and server. (Part of the MYNetwork code was originally adapted from it.)
—Jens
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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