Stream programming: premature 'end encountered' event
Stream programming: premature 'end encountered' event
- Subject: Stream programming: premature 'end encountered' event
- From: "Arthur C." <email@hidden>
- Date: Tue, 05 Sep 2006 18:41:10 +0200
I want to access a hardware device for data acquisition using TCP/IP. For
this I have used the code in the Stream Programming Guide for Cocoa to make
a test program.
The network traffic should be as follows: every 1/4 second, write to the
device to ask for the latest data (this is done using a timer loop). Then,
the device returns the data (about 16 bytes), which are read out in the
event handler. Meanwhile, make sure that we don't ask for new data as long
as the current data has not been returned.
However, after just one write/read cycle, I'm unable to obtain new data.
Right after the second time I write data to the stream (using the code at
page 17 of the stream programming guide), an event occurs with the code
'NSStreamEventEndEncountered' (from the output stream), after which the
stream should be disposed of, according to the programming guide. This is
not what I want, as I need to loop indefinitely as described above.
In the programming guide it says (page 17): "When an NSOutputStream
concludes writing data to an output stream, it sends the delegate a
NSStreamEventEndEncountered event". Does this mean that I can write to a
stream only once, and have to close, release it and make a new one?
If so, why does it occur after the second attempt to write to it, and not
after the first attempt has finished?
If not, what has to be done to allow multiple writes?
So the event sequence is:
NSStreamEventOpenCompleted [read]
NSStreamEventOpenCompleted [write]
NSStreamEventHasSpaceAvailable [write]
now write data to stream
NSStreamEventHasSpaceAvailable [write]
NSStreamEventHasBytesAvailable [read]
read data from stream
and write new data to stream
NSStreamEventEndEncountered [write]
no more events received
and the code in the timer handler is as follows:
- (void) testTimer: (NSTimer *) timer
{
int iStreamStatus = [iStream streamStatus];
int oStreamStatus = [oStream streamStatus];
if( [self spaceAvailable] == YES && [self frequencyRead] == YES &&
[oStream streamStatus] == NSStreamStatusOpen)
{
[self writeDataToStream];
[self setSpaceAvailable: NO];
[self setFrequencyRead: NO];
}
}
Thanks in advance,
Arthur C.
_________________________________________________________________
Play online games with your friends with MSN Messenger
http://www.join.msn.com/messenger/overview
_______________________________________________
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