At some point I got interested in how to communicate with a USENET (news/nntp) server. I couldn't find any classes on the internet that would help me, so I wrote my own.
To connect to a news-server you need to communicate through the NNTP protocol. It's a really simple text-string based protocol, consisting of several new-line separated commands that always result in a reply in the form of another formatted text-string.
This code was actually going to be a real application, when I discovered that I could pretty much do the same with MS Outlook Express, and as the NNTP protocol didn't turn out to be such a challenge, I lost interest in completing the class with all the NNTP commands (e.g. reading and posting news articles).
The Source Code
The CNntpSession Class
TheCNntpSession
class extends the CSocket
MFC class.
It implements basic communication with a news server.
It is just as easy to use as the usual MFC CHttpSession
and CInternetSession
classes.
What else is in there
Besides from getting News group information, the application uses Pattern Matching to filter the list. It also uses multi-threading to be able to seamlessly update the article count as results come in from the NNTP queries.The source files also contain a RFC document describing the NNTP protocol commands, so you can easily extend the class for your own needs.
Interface
Name | Description | |
---|---|---|
Connect | Connects to a USENET server. | |
GetGroups | Returns the list of available groups. | |
SelectGrounp | Select a group. | |
GetArticleHeaders | Returns the number of headers available. | |
Close | Closes the connection. |
Code Features
- NNTP communication class.
- Property Pages in dialog.
- Pattern Matching.
- Multi-threaded list updates.
TODO List
- Make the NNTP class asynchronous.
Source Code Dependencies
Microsoft Visual C++ 6.0Microsoft MFC Library
Installation Guide
- Start the application. Immediately switch to the second page. On this page, enter the connect string for the news server you wish to connect to (usually the format is something like this: news.server.com). Also choose a port, and if required, a username and password for the USENET server.
- If this is your first visit, press the "Download Group List" button to download the complete list of groups available. This will take some time. When the list is downloaded, switch to the last page.
- The last page will instantly be updated with the complete list of groups. When all groups are added to the list, each group is queried for the available number of articles and the list is updated.
- Enter a filter to minimize the number of groups. A common filter could be "rec.games.computer".
Download Files
Binary Files (13 Kb) Source Code (45 Kb) |