How to NNTP in C#

Using the NNTP class

Using our NNTP class is quite trivial. An example follows.

static void Main(string[] args)
{
    try
    {
        Nntp obj = new Nntp();
        obj.Connect(" news.devx.com");
        ArrayList list = obj.GetNewsgroups();
        foreach (string newsgroup in list)
        {
            System.Console.WriteLine(" Newsgroup :{0}",
                newsgroup);
        }
        list = obj.GetNews(" test");
        foreach (string article in list)
        {
            System.Console.WriteLine("{0}", article);
        }
        obj.Post(" test", "Hello",
            "randy@ kbcafe.com (Randy Charles Morin)", "Goodbye");
        obj.Disconnect();
    }
    catch (NntpException e )
    {
        System.Console.WriteLine(e.ToString());
    }
    catch (System.Exception )
    {
        System.Console.WriteLine(" Unhandled Exception");
    }
}

Instantiate an Nntp object and call Connect passing the NNTP server name. Then we can repeatedly call GetNewsgroups, GetNews and Post to receive and post articles in the forums found on the NNTP server. Finally you call the Disconnect method to release the socket connection to our NNTP server.

The RFC for NNTP is RFC 977 and can be found at the IETF website. You should also review the RFC for the USENET news message format as presented in RFC 850.

You might also like...

Comments

About the author

Randy Charles Morin

Randy Charles Morin Canada

Randy's article are Copyright 1998-2003 Randy Charles Morin

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Computer Science is no more about computers than astronomy is about telescopes.” - E. W. Dijkstra