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: Ken Thomases <email@hidden>
- Date: Fri, 10 Jun 2011 22:01:08 -0500
On Jun 10, 2011, at 7:35 PM, email@hidden wrote:
> I want the TCPServer to return some data block to each client that connects. I basically just want to put the bytes of the NSData object one after another on the outputstream that is connected to the socket.
> Problem: I would have to save the position in the data for each client to return the correct bytes to the client. At that point I thought that's what streams are for. To save your current position in a blob of bytes that should be read in order.
> Solution: Create a new NSInputStream (independent from the input stream of the TCPServer. That's why I talked about the data input stream, the input stream that reads the bytes of the data object) for each incoming connection. Guessing that after the NSInputStream based on the data is open it won't have any problems reading the data I only wait for the output stream to have space available and whenever it has I read some bytes from the data input stream and write them on the server output stream. I completely ignore the server input stream (except for logging the received data, when searching for bugs).
When the client can accept data, you can just read from the input stream. If you get a zero-length read, then the input stream is exhausted. You may not get an event for that. In fact, the input stream need not be scheduled on a run loop and, if it's not, the delegate won't get any calls. The events and the delegate are for asynchronous events in the stream, and there are none for a stream based on a data object.
Regards,
Ken
_______________________________________________
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