NSStream or when NSStreamEventEndEncountered appears too late

  • Hello,

    I'm studying the NSStream class and its concrete subclasses.
    For that i wrote a very simple NNTP (usenet) client app.

    In this application i use the run-loop scheduling streams technique.

    I'm able to catch all stream events but NSStreamEventEndEncountered
    appears about 4 minutes after reading the last NNTP response (i.e. the
    end of the input stream) :

    If i send the "LIST" command (give me the list of the newsgroups) to
    the NNTP server, i receive the response via several
    NSStreamEventHasBytesAvailable events. In the NNTP protocol the end of
    a response for such a command is @".\r\n" sequence. I have this
    sequence in an ultimate NSStreamEventHasBytesAvailable event.
    For me it means the end of the input stream, but the
    NSStreamEventEndEncountered event comes 4 minutes after... and there
    is no other event between the end of the response and the end event.

    The apple doc says "....When an NSInputStream object reaches the end
    of a stream, it sends the delegate a NSStreamEventEndEncountered
    event...". Maybe i didn't well understand what "end of a stream"
    really means.

    Do you have an idea why i receive the NSStreamEventEndEncountered
    event so long after the last NSStreamEventHasBytesAvailable ?

    Thanks a lot for your help,
    K.
  • On 21 Nov 07, at 14:44, Kubernan At 10191 Technologies wrote:
    > I'm studying the NSStream class and its concrete subclasses.
    > For that i wrote a very simple NNTP (usenet) client app.
    >
    > In this application i use the run-loop scheduling streams technique.
    >
    > I'm able to catch all stream events but NSStreamEventEndEncountered
    > appears about 4 minutes after reading the last NNTP response (i.e.
    > the end of the input stream) :
    >
    > If i send the "LIST" command (give me the list of the newsgroups) to
    > the NNTP server, i receive the response via several
    > NSStreamEventHasBytesAvailable events. In the NNTP protocol the end
    > of a response for such a command is @".\r\n" sequence. I have this
    > sequence in an ultimate NSStreamEventHasBytesAvailable event.
    > For me it means the end of the input stream, but the
    > NSStreamEventEndEncountered event comes 4 minutes after... and there
    > is no other event between the end of the response and the end event.
    >
    > The apple doc says "....When an NSInputStream object reaches the end
    > of a stream, it sends the delegate a NSStreamEventEndEncountered
    > event...". Maybe i didn't well understand what "end of a stream"
    > really means.
    >
    > Do you have an idea why i receive the NSStreamEventEndEncountered
    > event so long after the last NSStreamEventHasBytesAvailable ?

    "End of a stream" means the connection has closed down completely -
    this is apparently only happening after the server times out. There's
    no application-independent way to detect the end of an individual
    transmission on a TCP stream; you'll need to detect the end-of-listing
    marker yourself and respond to it yourself.
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today