AspNNTP Sample Code

AspNNTP allows you to retrieve and post articles to standard NNTP (Usenet/News) servers. Features include:

  • Retrieving Articles
  • Posting Articles
  • Multiple File Attachments
  • File attachments support MIME and UUEncoding
  • US Ascii and ISO-8859-1 character sets
  • PGP Support
  • Multiple concurrent users (Tested with 15 concurrent connections)

 

  rem *************************************************************************  
  rem *  Instantiate the NNTP object  
  rem *************************************************************************  
  Set NNTP = Server.CreateObject("AspNNTP.Conn")  
 
  rem *************************************************************************  
  rem *  Set the news server name  
  rem *************************************************************************  
  NNTP.Server = "msnews.microsoft.com" 
 
  rem *************************************************************************  
  rem *  Set the news group to return articles from  
  rem *************************************************************************  
  if NNTP.SetNewsgroup ("microsoft.public.inetserver.misc") then  
    Response.Write "First 10 postings - <p><table width="90%" border=1>"  
 
    For intCount = 1 to 10  
      rem *************************************************************************  
      rem *  Retrieve the article by number  
      rem *************************************************************************  
      NNTP.GetArticleByNumber(NNTP.CurrentArticle)  
      Response.Write "<tr><td>" & NNTP.CurrentArticle & "</td><td>" & NNTP.Subject & "</td><td>" & NNTP.BodyText & "</td></tr>"  
 
      rem *************************************************************************  
      rem *  Point CurrentArticle to the next legal article number  
      rem *  Note: Use this rather than looping from FirstArticle to LastArticle  
      rem *        since some articles may no longer exist  
      rem *************************************************************************  
      NNTP.NextArticle  
    Next  
    Response.Write "</table>"  
 
  else  
    Response.Write "<p>Unable to open Server or Newsgroup<br>" & VbCrLf  
    Response.Write "Failure was: " & NNTP.Response & "</p>" & VbCrLf  
  end if  
 
  rem *************************************************************************  
  rem *  Make sure the object is destroyed  
  rem *************************************************************************  
  Set NNTP = nothing 
%>  

 

Notes About Creating the NNTP Object

You can create the NNTP object at two different points in time:

  • Immediately before retrieving or posting an article
  • At the session scope and saved as a session object

You will have to decide when and where it is appropriate to create the object based on your particular application. If you aren't sure which way to create the object reference, or for typical usage, you should create the object immediately usage. Your code would look like this:

Set NNTP = Server.CreateObject("AspNNTP.Conn")

Creating these local references, as demonstrated above, allow you to use the object on multiple application threads at the same time.

To create an object reference at the session level, your code might look something like this:

if Not IsObject (session("NNTP")) then Set NNTP = Server.CreateObject("AspNNTP.Conn") Set session("NNTP") = NNTPelse Response.write "Cached session object reference being used<p>" Set NNTP = session("NNTP")end if

Article ID: 324, Created On: 4/24/2009, Modified: 4/25/2009