Home >Backend Development >PHP Tutorial >Using sockets to get articles from newsgroups 2_PHP tutorial
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 successfully executed. 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";