SocketTools .NET Edition

Network News Transfer Protocol

The Network News Transfer Protocol (NNTP) class enables applications to access a news server, list the available newsgroups, retrieve articles and post new articles. It is common for this class to be used in conjunction with the Mail Message class to construct the articles, since a news article uses the same general format as an email message.

Initialization

Initialize
Initialize an instance of the class, loading the networking library and validating the development license. This method must be called before any properties are changed or any other methods in this class are called by the application.

Connect
Establish a connection to the server. Once the connection has been established, the other methods in the class may be used to access the messages on the server.

Disconnect
Disconnect from the server and release the memory allocated for that client session. After this method is called, the client session is no longer valid.

Reset
Reset the internal state of the component. This can be useful if your application wishes to discard any settings made by a user and return that instance of the class to its default state.

Uninitialize
Unload the networking library and release any resources that have been allocated for the current process. This is the last method call that the application should make prior to terminating. This is only necessary if the application has previously called the Initialize method.

Newsgroups

News articles are posted in hierarchical groups, similar to how files are stored in folders. Each level in the newsgroup hierarchy is separated by a period, so newsgroup names look like microsoft.public.vc. This is Microsoft's newsgroup for articles about Visual C++ programming. Additional subgroups are used to further narrow the topic; for example, there's the microsoft.public.vc.3rdparty newsgroup for third party tools and components for Visual C++, and the microsoft.public.vc.atl newsgroup which discusses issues related to the ActiveX Template Library. The NNTP class provides the following methods for accessing newsgroups on the server:

GetFirstGroup
This method returns the first available newsgroup on the server. This method is used in conjunction with the GetNextGroup method to enumerate all of the available newsgroups. An overloaded implementation of this method also enables you to specify a date value, where only those newsgroups created on or after that date are returned. This is useful for updating a locally stored list of newsgroups without downloading the complete list of newsgroups each time the client connects to the server.

GetNextGroup
This method returns the next available newsgroup on the server and is used in conjunction with the GetFirstGroup method.

SelectGroup
This method is used to select a newsgroup as the current group. Once selected, the application has access to the articles in that newsgroup.

News Articles

News articles are the messages posted to one or more newsgroups. Articles are referenced by their article number, which is a value assigned by the news server. These articles have a structure that is the same as an email message, with some slightly different headers. Because of this, you can use the Mail Message interface to parse articles that you retrieve, as well as create new articles to post to the server. The following methods are used to access and create news articles:

GetFirstArticle
This method returns information about the first available article in the currently selected newsgroup. This method is used in conjunction with the GetNextArticle method to enumerate all of the available articles in a newsgroup. An overloaded implementation of this method also enables you to specify a starting and ending article number, which enables you to only list those articles within a specific range.

GetNextArticle
This method returns the next available article and is used in conjunction with the GetFirstArticle method.

GetArticle
Retrieve an article from the server, storing the contents in a string buffer or byte array. This can be used to process the contents of an article without the overhead of storing it in a file on the local system.

StoreArticle
Retrieve an article from the server and store it in a file on the local system.

PostArticle
This method posts an article to one or more newsgroups on the server. A newsgroup article is similar to an email message, and the MIME interface may be used to create the article headers and body. One important difference is that the message must contain a header named "Newsgroups" with the value set to the newsgroup or newsgroups that the article should be posted to; multiple newsgroups should be separated by commas. If this header is not defined, the posting will be rejected by the server and the method will return an error. You should also be aware that some servers limit the number of newsgroups that a message can be posted to. When an article is posted to more than one newsgroup at a time, this is called cross-posting. Current convention says that an article should not be cross-posted to more than five newsgroups at a time. Also keep in mind that multiposting (posting the same article to different newsgroups separately) is generally discouraged and should never be done on USENET.

Attaching Files

It is possible to attach files to newsgroup articles; however it should only be done if it is considered appropriate for the group. Many newsgroups have their own acceptable use policies which determine whether or not file attachments, particularly large binary files, are acceptable. If the newsgroup accepts attachments, you can use one of several methods for posting files. It is recommended that you use the File Encoding interface to handle the actual encoding of the data.

Uuencode
A uuencoded file attachment is included directly in the body of the message. Because the MIME interface creates a multipart message even when uuencoding is specified, the File Encoding interface should be used to encode the data and then it should be included in the main body of the message.

Base64
A Base64 file attachment has the same structure as what is used by email messages. This requires that a multipart message be created, with the encoded data attached as a part of the message. You can use the MIME class to create this kind of message. Note that not all third-party newsreaders correctly handle multipart messages.

yEnc
The newest encoding method used on USENET is called yEnc. Similar to uuencoded attachments, the file data is part of the body of the message. The File Encoding class should be used to encode the data and then it should be included in the main body of the message. More information about yEnc encoding can be found at www.yenc.org