Home  >  Article  >  Backend Development  >  Using sockets: Get articles from newsgroups (2)_PHP tutorial

Using sockets: Get articles from newsgroups (2)_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 16:06:47824browse

Talk to the server
Now that we have connected to the server, we can talk to the server through the socket opened earlier. For example, let's say we want to get the last 10 articles from a certain news group. RFC977 points out that the first step is to use the GROUP command to select the correct news group:
GROUP ggg
The parameter ggg is the name of the news group to be selected (for example, "net.news"), which is required. A list of available newsgroups can be obtained with the LIST command. When the command to select a newsgroup succeeds, it returns the article numbers of the first and last articles in the group, as well as 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 '^]'.
200 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 RFC, indicating that the command has been executed successfully. The return information also points out that there are now 232 articles, the earliest article number is 222996, and the latest article number is 223235. We see that 222996+232 is not equal to 223235. The missing 7 articles were deleted from the server for some reason, either because they were canceled by their legitimate authors (which is possible and easy to do), or because they were spam articles.
Something to note, some servers may require authentication before selecting a news group, depending on whether it is a public or private server. It's also possible that the server allows anyone to read the article, but publishing the article requires authentication.


//$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"); //check error

                                                                                                            }

//select newsgroup

fput($usenet_handle, "GROUP ".$cfgNewsGroup."n");
$tmp = fgets($usenet_handle, 1024);

if($ tmp == "480 Authentication required for commandrn") {
echo $tmp;
exit();
}

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

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

?>



http://www.bkjia.com/PHPjc/315325.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/315325.htmlTechArticleTalk to the server Now that we have connected to the server, we can talk to the server through the socket opened earlier. For example, let's say we want to get the last 10 articles from a certain news group. ...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn