How to use fgets() with a NNTP server?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • test

    How to use fgets() with a NNTP server?

    Hi,

    I am using fgets() to recieve an article from a NNTP server.
    The articles end with:

    ..

    or in other words: <crlf>.<crlf>

    My code that reads the article always hangs when it reaches
    the end, and I don't understand why. Can you help me write the
    condition for the while() statement? This is the code:

    fputs($soket, "article 91500\n");
    $t = fgets($soket, 1024);

    $i=0;
    // OK so far

    while ($t != ".") { // this doesn't work, nor does ".\n"
    $i++;
    $sve[$i] = $t;
    $t = fgets($soket, 1024);
    }
  • test

    #2
    Re: How to use fgets() with a NNTP server?

    On Fri, 7 Apr 2006 11:57:35 +0200, test wrote:
    [color=blue]
    > Hi,
    >
    > I am using fgets() to recieve an article from a NNTP server.
    > The articles end with:
    >
    > .
    >
    > or in other words: <crlf>.<crlf>
    >
    > My code that reads the article always hangs when it reaches
    > the end, and I don't understand why. Can you help me write the
    > condition for the while() statement? This is the code:
    >
    > fputs($soket, "article 91500\n");
    > $t = fgets($soket, 1024);
    >
    > $i=0;
    > // OK so far
    >
    > while ($t != ".") { // this doesn't work, nor does ".\n"
    > $i++;
    > $sve[$i] = $t;
    > $t = fgets($soket, 1024);
    > }[/color]

    It seems that fgets() *waits* for input if there is none. How
    can I prevent it? Or is there an alternative function? also, I
    should still get to the dot *before* I get to the end of
    transmission.

    Comment

    • Tim Van Wassenhove

      #3
      Re: How to use fgets() with a NNTP server?

      On 2006-04-07, test <test@test.test > wrote:[color=blue]
      > I am using fgets() to recieve an article from a NNTP server.
      > The articles end with:
      > or in other words: <crlf>.<crlf>
      > while ($t != ".") { // this doesn't work, nor does ".\n"[/color]

      So you only tested with . and .<lf>
      What happens if you try to read until ".\r\n"?
      (and the previous line was "\r\n")


      --
      Met vriendelijke groeten,
      Tim Van Wassenhove <http://timvw.madoka.be >

      Comment

      • test

        #4
        Re: How to use fgets() with a NNTP server?

        On Fri, 7 Apr 2006 10:30:26 +0000 (UTC), Tim Van Wassenhove
        wrote:
        [color=blue]
        > On 2006-04-07, test <test@test.test > wrote:[color=green]
        >> I am using fgets() to recieve an article from a NNTP server.
        >> The articles end with:
        >> or in other words: <crlf>.<crlf>
        >> while ($t != ".") { // this doesn't work, nor does ".\n"[/color]
        >
        > So you only tested with . and .<lf>
        > What happens if you try to read until ".\r\n"?[/color]

        Neither ".\r\n" nor ".\n\r" work, which is really weird.

        Comment

        • test

          #5
          Re: How to use fgets() with a NNTP server?

          On Fri, 7 Apr 2006 10:30:26 +0000 (UTC), Tim Van Wassenhove
          wrote:
          [color=blue]
          > On 2006-04-07, test <test@test.test > wrote:[color=green]
          >> I am using fgets() to recieve an article from a NNTP server.
          >> The articles end with:
          >> or in other words: <crlf>.<crlf>
          >> while ($t != ".") { // this doesn't work, nor does ".\n"[/color]
          >
          > So you only tested with . and .<lf>
          > What happens if you try to read until ".\r\n"?
          > (and the previous line was "\r\n")[/color]

          Upon futher testing, ".\r\n" indeed works :)
          Thanks, Tim.

          Comment

          • void * clvrmnky()

            #6
            Re: How to use fgets() with a NNTP server?

            test wrote:[color=blue]
            > On Fri, 7 Apr 2006 10:30:26 +0000 (UTC), Tim Van Wassenhove
            > wrote:
            >[color=green]
            >> On 2006-04-07, test <test@test.test > wrote:[color=darkred]
            >>> I am using fgets() to recieve an article from a NNTP server.
            >>> The articles end with:
            >>> or in other words: <crlf>.<crlf>
            >>> while ($t != ".") { // this doesn't work, nor does ".\n"[/color]
            >> So you only tested with . and .<lf>
            >> What happens if you try to read until ".\r\n"?
            >> (and the previous line was "\r\n")[/color]
            >
            > Upon futher testing, ".\r\n" indeed works :)
            > Thanks, Tim.[/color]

            You may want to accept the other combinations of line-ends, as well,
            perhaps issuing a warning. The specification demands that "\r\n" be
            used in NNTP messages, but there are a lot of poorly written servers out
            there.

            You do not want to get into the trap of being so true to the standard
            that you end up reading it the way the devil reads the bible.
            Admittedly, this is more of a problem for SMTP messaging.

            Comment

            • Tim Van Wassenhove

              #7
              Re: How to use fgets() with a NNTP server?

              On 2006-04-07, void * clvrmnky() <clvrmnky.inval id@hotmail.com. invalid> wrote:[color=blue]
              > test wrote:[color=green]
              >> On Fri, 7 Apr 2006 10:30:26 +0000 (UTC), Tim Van Wassenhove
              >> wrote:
              >>[color=darkred]
              >>> On 2006-04-07, test <test@test.test > wrote:
              >>>> I am using fgets() to recieve an article from a NNTP server.
              >>>> The articles end with:
              >>>> or in other words: <crlf>.<crlf>
              >>>> while ($t != ".") { // this doesn't work, nor does ".\n"
              >>> So you only tested with . and .<lf>
              >>> What happens if you try to read until ".\r\n"?
              >>> (and the previous line was "\r\n")[/color]
              >>
              >> Upon futher testing, ".\r\n" indeed works :)
              >> Thanks, Tim.[/color]
              >
              > You may want to accept the other combinations of line-ends, as well,
              > perhaps issuing a warning. The specification demands that "\r\n" be
              > used in NNTP messages, but there are a lot of poorly written servers out
              > there.
              >
              > You do not want to get into the trap of being so true to the standard
              > that you end up reading it the way the devil reads the bible.
              > Admittedly, this is more of a problem for SMTP messaging.[/color]

              In analogy with HTTP i tende to be as forgiving as possible.
              In case of the line-ending i usually rtrim the line and then analyse the
              content without <cr|crlf|lf| ... > ending.

              --
              Met vriendelijke groeten,
              Tim Van Wassenhove <http://timvw.madoka.be >

              Comment

              Working...