Using sockets: Getting articles from newsgroups (ii)

Source: Internet
Author: User
Tags exit printf
Talking to the server
Now that we have connected to the server, we can talk to the server through the socket we opened earlier. Let's say we get the last 10 articles from a newsgroup. RFC977 points out that the first step is to select the correct newsgroup with the group command:
GROUP GGG
Parameter GGG is the name of the newsgroup you want to select (for example, "Net.news"), which is required. Lists of available newsgroups can be obtained by using the List command. When the command to select a newsgroup succeeds, returns the article number of the first and last articles in the group, and the number of articles in the group.
Here is an example:
chrome:~$ Telnet My.news.host 119
Trying aa.bb.cc.dd ...
Connected to My.news.host.
Escape character is ' ^] '.
My.news.host internetnews NNRP Server INN 2.2.2 13-dec-1999 ready (posting OK).
GROUP Alt.test
211 232 222996 223235 Alt.test
Quit
205.

After receiving the command GROUP alt.test, the server returns "211 232 222996 223235 alt.test". 211 is the return code defined in the RFC, indicating that the command was executed successfully. The return information also points out that there are now 232 articles, the earliest article is numbered 222996, and the latest article is numbered 223235. We see that 222996+232 is not equal to 223235. The missing 7 articles were deleted from the server for some reason, possibly because it was canceled by its rightful author (which is possible, and it is easy to do), or deleted because it is an irrigation article.
To be aware, some servers may require authentication before they select newsgroups, depending on whether they are a public or private server. It is also possible that the server allows anyone to read the article, but it requires authentication to publish the article.

<?php

$cfgUser = "xxxxxx";
$CFGPASSWD = "yyyyyy";
$cfgNewsGroup = "alt.php";

Identification required on private server
if ($cfgUser) {
Fputs ($usenet _handle, "AUTHINFO USER". $cfgUser. " n ");
$tmp = fgets ($usenet _handle, 1024);
Fputs ($usenet _handle, "AUTHINFO Pass". $cfgPasswd. " n ");
$tmp = fgets ($usenet _handle, 1024);

Check error

if ($tmp!= "281 okrn") {
echo "502 Authentication Errorn";
Exit ();
}
}

Select newsgroup

Fput ($usenet _handle, "GROUP". $cfgNewsGroup. " n ");
$tmp = fgets ($usenet _handle, 1024);

if ($tmp = = "Authentication required for Commandrn") {
Echo $tmp;
Exit ();
}

$info = Split ("", $tmp);
$first = $info [2];
$last = $info [3];

printf ("A:%sn", $first);
printf ("Last:%lastn", $last);

?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.