473,385 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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);
}
Apr 7 '06 #1
6 1464
On Fri, 7 Apr 2006 11:57:35 +0200, test wrote:
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);
}


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.
Apr 7 '06 #2
On 2006-04-07, test <te**@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")
--
Met vriendelijke groeten,
Tim Van Wassenhove <http://timvw.madoka.be>
Apr 7 '06 #3
On Fri, 7 Apr 2006 10:30:26 +0000 (UTC), Tim Van Wassenhove
wrote:
On 2006-04-07, test <te**@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"?


Neither ".\r\n" nor ".\n\r" work, which is really weird.
Apr 7 '06 #4
On Fri, 7 Apr 2006 10:30:26 +0000 (UTC), Tim Van Wassenhove
wrote:
On 2006-04-07, test <te**@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")


Upon futher testing, ".\r\n" indeed works :)
Thanks, Tim.
Apr 7 '06 #5
test wrote:
On Fri, 7 Apr 2006 10:30:26 +0000 (UTC), Tim Van Wassenhove
wrote:
On 2006-04-07, test <te**@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")


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


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.
Apr 7 '06 #6
On 2006-04-07, void * clvrmnky() <cl**************@hotmail.com.invalid> wrote:
test wrote:
On Fri, 7 Apr 2006 10:30:26 +0000 (UTC), Tim Van Wassenhove
wrote:
On 2006-04-07, test <te**@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")


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


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.


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>
Apr 7 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Alex Shi | last post by:
Hi all, Please take a look at following very simple script; #!/usr/bin/php -q <? echo "Hello, world!\n"; if (!$tty) { $tty = fopen('php://stdin', 'r'); }
8
by: Roland Hall | last post by:
Is it possible to send/receive nntp messages via CDOSYS without a 3rd party news component? The NNTP links I have found appear to be related to MS Exchange 2K. My goal is to write an ASP...
3
by: J.Marsch | last post by:
For the past few days, I've been getting really poor performance with these newgroups (use Outlook Express 6 as my NNTP reader), and sometimes it will completely fail download a message, and I have...
11
by: Jim | last post by:
Have you seen any NNTP classes that I may use or build upon to build a simple newsreader/downloader? Is there such a class in the .Net framework that I have overlooked? If not, inclusion of RFC...
9
by: Sandman | last post by:
Ok, I do NOT want to *connect* to a NNTP server from PHP, I want to - from a NNTP client - connect to a NNTP server that is powered by PHP. Specifically, I want articles, forum posts and such...
0
by: smritikapoor | last post by:
I am trying to connect to an https server using NNTP perl module. I have been able to connect to normal NNTP server using the NNTP perl module but cannot connect to an https server. Please help me...
4
by: BiT | last post by:
Hi i'm trying to code simple nntp client with vb.net and sockets client class the problem is the machine keep stuck (probbley beacuse it ain't gettin` data from the server) after the user name...
3
by: Alexander Higgins | last post by:
Hi, I am working on an NNTP Client via windows forms and am actually try to login into this group to no avail. I am sending AUTHINFO USER username <where username=myemail address AUTHINFO...
6
by: Gert Kok | last post by:
When fgets() reads a string that ands with <<<EOT, the string is truncated after << and a lot of following input is discarded. When <<<EOT is changed to <<< EOT, behaviour is as I expect it. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.