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: email@hidden
- Date: Fri, 10 Jun 2011 20:39:55 +0200
I tried around a bit more and still can't get it to work.
I will have a look at the MyNetwork Library you recommended now.
Still what I'm confused about:
Am 2. juni 2011 um 20.40 schrieb Jens Alfke:
> On Jun 2, 2011, at 2:10 AM, email@hidden wrote:
>>
>> I wanted to have a very basic TCP server that could return arbitrary bytes when a client connected to it to test whether some protocol (on top of TCP) code I wrote works as expected. To do so I adapted the CocoaEcho example (http://developer.apple.com/library/mac/samplecode/CocoaEcho/Introduction/Intro.html ).
>
>> But the inputDataStream seems to never get closed. I would have expected it to be closed when it reaches the end of the underlying data.
>
> No, that’s not how streams behave. They close when you close them, not automatically.
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.
But I do not get a NSStreamEventEndEncountered event in the delegate method. I would have expected it to be send when the stream is closed. In what cases would one get an NSStreamEventEndEncountered if it's not when the stream reaches the end of the data and it's not when the stream is closed?
Or is it because it is removed from the run loop when it is closed? But shouldn't it post the event first before removing itself from the runloop?
2. I also close the output stream of the server in this event. I would have expected the corresponding NSInputStream on the other end of the TCP connection (the client's NSInputStream) to be closed as well in that case. And then also send an NSStreamEventEndEncountered to its delegate. This does not seem to happen either. I ran it in the debugger to check that the output stream of the server is actually closed. And then let it run for a few second. But there were no other calls to any stream:handleEvent: (except for potentially delayed NSStreamEventHasByteAvailable events).
Can you explain this behaviour? Or is there something wrong?
Best regards,
Joachim
_______________________________________________
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