473,386 Members | 1,609 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Seeking NNTP classes.....

Jim
Have you seen any NNTP classes that I may use or build upon to build a
simple newsreader/downloader?

Is there such a class in the .Net framework that I have overlooked? If not,
inclusion of RFC documented protocols would certainly be a good idea for a
class hierarchy in the .Net classes.

You could adopt and extend the classes at will. Who knows......maybe even
improve one and get a new RFC implemented.

Any help you could give would be great. (FYI the RFCs for NNTP protocols
are at http://www.ietf.org/rfc/rfc0977.txt?number=977 and the RFC for the
USENET mail standard is at http://www.ietf.org/rfc/rfc0850.txt?number=850.)

Thanks!

Dec 13 '05 #1
6 1213
"Jim" <re***@groups.please> schrieb:
Have you seen any NNTP classes that I may use or build upon to build a
simple newsreader/downloader?


Accessing newsgroups with NNTP
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=nntp&lang=en>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Dec 13 '05 #2
Hi,

Here is some vb.net code I wrote based on this c# code.

http://www.developerfusion.co.uk/show/4472/

NNTP class
Imports System.Net.Sockets
Imports System.IO
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Binary

Public Class NNTP
Inherits System.Net.Sockets.TcpClient

Public Event MessageHeaderRecieved(ByVal sender As Object, ByVal e As
NNPTEventArgs)
Dim arNews As New NewsGroupMessageTable
Dim mstrGroupName As String

#Region "Message custom Hashtable"
<Serializable()> _
Private Class NewsGroupMessageTable
Inherits System.Collections.DictionaryBase
Default Public Property Item(ByVal key As [String]) As
NNTP.NewsGroupMessage
Get
Return CType(Dictionary(key), NNTP.NewsGroupMessage)
End Get
Set(ByVal Value As NNTP.NewsGroupMessage)
Dictionary(key) = Value
End Set
End Property

Public ReadOnly Property Keys() As ICollection
Get
Return Dictionary.Keys
End Get
End Property

Public ReadOnly Property Values() As ICollection
Get
Return Dictionary.Values
End Get
End Property

Public Sub Add(ByVal key As [String], ByVal value As
NNTP.NewsGroupMessage)
Dictionary.Add(key, value)
End Sub 'Add

Public Function Contains(ByVal key As [String]) As Boolean
Return Dictionary.Contains(key)
End Function 'Contains

Public Sub Remove(ByVal key As [String])
Dictionary.Remove(key)
End Sub 'Remove

End Class
#End Region

#Region "News group message class"
<Serializable()> _
Public Class NewsGroupMessage
Dim mstrSubject As String
Dim mstrTo As String
Dim mstrFrom As String
Dim mstrBody As String
Dim mdtMessage As Date
Dim intId As Long
Dim strRef As String = "None"

Public Property ID() As Long
Get
Return intId
End Get
Set(ByVal Value As Long)
intId = Value
End Set
End Property

Public Property MessageDate() As Date
Get
Return mdtMessage
End Get
Set(ByVal Value As Date)
mdtMessage = Value
End Set
End Property

Public Property Subject() As String
Get
Return mstrSubject
End Get
Set(ByVal Value As String)
mstrSubject = Value
End Set
End Property

Public Property From() As String
Get
Return mstrFrom
End Get
Set(ByVal Value As String)
mstrFrom = Value
End Set
End Property

Public Property Body() As String
Get
Return mstrBody
End Get
Set(ByVal Value As String)
mstrBody = Value
End Set
End Property

Public Property MessageReference() As String
Get
Return strRef
End Get
Set(ByVal Value As String)
strRef = Value
End Set
End Property
Public Property MessageTo() As String
Get
Return mstrTo
End Get
Set(ByVal Value As String)
mstrTo = Value
End Set
End Property
End Class

#End Region

#Region "NNPT event args"
Public Class NNPTEventArgs
Inherits EventArgs
Private mintMax As Long
Private mintpos As Long
Private mMessage As NewsGroupMessage

Public Sub New(ByVal max As Long, ByVal pos As Long, ByVal message
As NewsGroupMessage)
mintMax = max
mintpos = pos
mMessage = message
End Sub

Public ReadOnly Property Max() As Long
Get
Return mintMax
End Get
End Property

Public ReadOnly Property Pos() As Long
Get
Return mintpos
End Get
End Property

Public ReadOnly Property Message() As NewsGroupMessage
Get
Return mMessage
End Get
End Property
End Class
#End Region

Public Overloads Sub Connect(ByVal server As String)
Dim strResponse As String

Connect(server, 119)
strResponse = Response()
If strResponse.Substring(0, 3) <> "200" Then
Throw New NntpException(Response)
End If

End Sub 'Connect

Public Sub Disconnect()
Dim message As String
Dim strResponse As String

message = "QUIT" + vbCr + vbLf
Write(message)
strResponse = Response()
If strResponse.Substring(0, 3) <> "205" Then
'Throw New NntpException(Response)
End If
Dim strFile As String = String.Format("{0}.ngd",
CurrentNewsGroup.Replace(".", ""))

Dim fs As New FileStream(strFile, FileMode.OpenOrCreate)

'Get a Binary Formatter instance
Dim bf As New BinaryFormatter

'Serialize t
bf.Serialize(fs, arNews)

End Sub 'Disconnect

Public Function GetNewsgroups() As ArrayList
Dim message As String
Dim strResponse As String

Dim retval As New ArrayList

message = "LIST" & vbCr & vbLf
Write(message)
strResponse = Response()
If strResponse.Substring(0, 3) <> "215" Then
Throw New NntpException(Response)
End If

While True
strResponse = Response()
If strResponse = "." + vbCr + vbLf OrElse strResponse = "." +
vbLf Then
Return retval
Else
Dim seps As Char = " "c
Dim values As String() = strResponse.Split(seps)
retval.Add(values(0))
End If
End While

End Function 'GetNewsgroups

Private Function Response() As String
Dim enc As New System.Text.ASCIIEncoding
Dim serverbuff() As Byte = New [Byte](1023) {}
Dim stream As NetworkStream = GetStream()
Dim count As Integer = 0
While True
Dim buff() As Byte = New [Byte](1) {}
Dim bytes As Integer = stream.Read(buff, 0, 1)
If bytes = 1 Then
serverbuff(count) = buff(0)
count += 1

If buff(0) = Asc(vbLf) Then
Exit While
End If
Else
Exit While
End If
End While

Dim retval As String = enc.GetString(serverbuff, 0, count)
'Debug.WriteLine("READ:" + retval)
Return retval

End Function 'Response

Public Property CurrentNewsGroup() As String
Get
Return mstrGroupName
End Get
Set(ByVal Value As String)
mstrGroupName = Value
End Set
End Property

Public Sub GetNewsHeaders()
Dim message As String
Dim strResponse As String = "211"

If CurrentNewsGroup Is Nothing Then
MessageBox.Show("Set news group first")
Return
End If

message = "GROUP " + CurrentNewsGroup + vbCr + vbLf
Write(message)
strResponse = Response()
If strResponse.Substring(0, 3) <> "211" Then
Throw New NntpException(strResponse)
End If

Dim seps As Char = " "c
Dim values As String() = strResponse.Split(seps)

Dim start As Long = Int32.Parse(values(2))
Dim [end] As Long = Int32.Parse(values(3))

If start + 500 < [end] AndAlso [end] > 500 Then
start = [end] - 500
End If

Dim strFile As String = String.Format("{0}.ngd",
CurrentNewsGroup.Replace(".", ""))
If File.Exists(strFile) Then
Dim fs As New FileStream(strFile, FileMode.Open)

'Get a Binary Formatter instance
Dim bf As New BinaryFormatter

'Deserialize c from strFilename2
'Note that the deserialized object must be cast to the proper
type.
arNews = CType(bf.Deserialize(fs), NewsGroupMessageTable)

'Close the file and release resources (avoids GC delays)
fs.Close()

End If
Dim l As Long = 0
For Each c As NewsGroupMessage In arNews.Values
l += 1
RaiseEvent MessageHeaderRecieved(Me, New
NNPTEventArgs(arNews.Count, l, c))
Next

Dim i As Long
For i = [end] To start Step -1
If Not arNews.Contains(i.ToString) Then
message = "HEAD " & i & vbCr & vbLf
Write(message)
strResponse = Response()

If strResponse.Substring(0, 3) <> "423" Then

If strResponse.Substring(0, 3) <> "221" Then
Throw New NntpException(strResponse)
Else
Dim article As New NewsGroupMessage
article.ID = i
Dim intLine As Integer = 0
Dim strMessage As String

While True
strResponse = Response()
If strResponse = "." + vbCr + vbLf Then
Exit While
End If

If strResponse = "." + vbLf Then
Exit While
End If

If strResponse.IndexOf("From:") = 0 Then
article.From = strResponse.Substring(6)
ElseIf strResponse.IndexOf("Subject") = 0 Then
article.Subject = strResponse.Substring(9)
ElseIf strResponse.IndexOf("References:") = 0
Then
article.MessageReference =
strResponse.Substring(12)
ElseIf strResponse.IndexOf("Message-ID:") = 0
Then
strMessage = strResponse.Substring(12)
ElseIf strResponse.IndexOf("Newsgroups:") = 0
Then
article.MessageTo =
strResponse.Substring(12)
ElseIf strResponse.IndexOf("Date:") = 0 Then
Dim intEnd As Integer =
strResponse.IndexOf("-") - 6
If intEnd < 0 Then
intEnd = strResponse.IndexOf("+") - 6
End If
If intEnd < 0 Then
intEnd = strResponse.IndexOf("GMT") - 6
End If
article.MessageDate =
DateTime.Parse(strResponse.Substring(6, intEnd))
End If
intLine += 1
End While
If article.MessageReference = "None" Then
article.MessageReference = strMessage
arNews.Add(article.ID.ToString, article)
Dim z As Long = [end] - start
RaiseEvent MessageHeaderRecieved(Me, New
NNPTEventArgs([end] - start, z - (i - start), article))
End If
End If
End If
Next i
End Sub 'GetNews

Public Function GetNewsArticle(ByVal MessageID As Long) As String
Dim message As String
Dim strResponse As String

If CurrentNewsGroup Is Nothing Then
MessageBox.Show("Set news group first")
Return Nothing
End If

message = "GROUP " + CurrentNewsGroup + vbCr + vbLf
Write(message)
strResponse = Response()
If strResponse.Substring(0, 3) <> "211" Then
Throw New NntpException(strResponse)
End If

message = "BODY " & MessageID.ToString & vbCr & vbLf
Write(message)
Dim article As String
strResponse = Response()

If strResponse.Substring(0, 3) <> "423" Then

If strResponse.Substring(0, 3) <> "222" Then
Throw New NntpException(strResponse)
Else
Dim intLine As Integer = 0
Dim strMessage As String

While True
strResponse = Response()
If strResponse = "." + vbCr + vbLf Then
Exit While
End If

If strResponse = "." + vbLf Then
Exit While
End If

article &= strResponse
End While
DirectCast(arNews.Item(MessageID.ToString),
NewsGroupMessage).Body = article
End If
End If
Return article

End Function 'GetNews

Public Sub Post(ByVal newsgroup As String, ByVal subject As String,
ByVal from As String, ByVal content As String)
Dim message As String
Dim strResponse As String

message = "POST " & newsgroup & vbCr & vbLf
Write(message)
strResponse = Response()
If strResponse.Substring(0, 3) <> "340" Then
Throw New NntpException(Response)
End If

message = "From: " & from & vbCr & vbLf & "Newsgroups: " & newsgroup
& vbCr & vbLf & "Subject: " & subject & vbCr & vbLf & vbCr & vbLf & content
& vbCr & vbLf & "." & vbCr & vbLf
Write(message)
strResponse = Response()
If strResponse.Substring(0, 3) <> "240" Then
Throw New NntpException(Response)
End If

End Sub 'Post

Private Sub Write(ByVal message As String)
Dim en As New System.Text.ASCIIEncoding

Dim WriteBuffer(1023) As Byte
WriteBuffer = en.GetBytes(message)

Dim stream As NetworkStream = GetStream()
stream.Write(WriteBuffer, 0, WriteBuffer.Length)

'Debug.WriteLine("WRITE:" & message)

End Sub 'Write
End Class

Public Class NewsGroupMessageCollection
Inherits System.Collections.CollectionBase
Public Sub Add(ByVal value As NNTP.NewsGroupMessage)
list.Add(value)
End Sub

Public Sub Remove(ByVal Index As Integer)
If Index > Count - 1 Or Index < 0 Then
Throw New Exception("Invalid Index")
Else
list.RemoveAt(Index)
End If
End Sub

Public ReadOnly Property Item(ByVal Index As Integer) As
NNTP.NewsGroupMessage
Get
Return CType(list.Item(Index), NNTP.NewsGroupMessage)
End Get
End Property
End Class


Public Class NntpException
Inherits System.ApplicationException

Public Sub New(ByVal str As String)
MyBase.New(str)

End Sub 'New
End Class 'NntpException

Ken
------------------
"Jim" <re***@groups.please> wrote in message
news:yq*******************@bignews4.bellsouth.net. ..
Have you seen any NNTP classes that I may use or build upon to build a
simple newsreader/downloader?

Is there such a class in the .Net framework that I have overlooked? If
not,
inclusion of RFC documented protocols would certainly be a good idea for a
class hierarchy in the .Net classes.

You could adopt and extend the classes at will. Who knows......maybe even
improve one and get a new RFC implemented.

Any help you could give would be great. (FYI the RFCs for NNTP protocols
are at http://www.ietf.org/rfc/rfc0977.txt?number=977 and the RFC for the
USENET mail standard is at
http://www.ietf.org/rfc/rfc0850.txt?number=850.)

Thanks!

Dec 13 '05 #3
Jim
Thanks for the jumping off point!

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:O8*************@TK2MSFTNGP12.phx.gbl...
Hi,

Here is some vb.net code I wrote based on this c# code.

http://www.developerfusion.co.uk/show/4472/

Dec 13 '05 #4
> Have you seen any NNTP classes that I may use or build upon to build a

simple newsreader/downloader?

Jim there is an NNTP demo included in IPWorks.
The NNTP component implements all of the protocol for you - leaving you with a
very simple API to work with. If you need more sample code, let me know, we've
got plenty.

Regards,
Lance R.
/n software
http://www.nsoftware.com/

-

Dec 13 '05 #5
Jim
Thanks Lance, but this is for a freeware project. While I am certain that
your components are of impeccable quality and that they are very easy to
use, I cannot justify the $400 price tag for a freeware project.

With the .Net components that I have worked with thus far (and I have not
worked with IPWorks yet) I cringe at the very thought of spending more than
$100 on any component. The components that I have used this far miss the
marks of ease-of-use set by the COM components I was used to (pre- this .Net
disaster) by a mile.

They are neither intuitive nor easy to use. I will reserve judgment on
IPWorks until I have some extra time to play with a demo, but, to be quite
honest, if IPWorks is intuitive or as easy to use as the old COM components
that used extensively I would be shocked.

It is also a sad commentary on the devastation that Microsoft has wrought
throughout its own industry that the component developers didn't have
anything ready for .Net 2.0 at its launch. That means that they aren't
making enough money off of components to put the needed resources on the
projects that need upgrading for .Net 2.0. And, that means that the masses
of VB programmers that used to buy components like crack whores needing a
fix just aren't programming any more.

I suppose that's a major reason for the free Express editions of VS 2005.
Trying to get back what they scattered.

Alas, it may be too little, too late. As Microsoft is (and its component
developers are) learning.....it's damned hard to put Humpty back together
again.
"Lance R." <la****@nsoftware.removeme.com> wrote in message
news:OO**************@TK2MSFTNGP10.phx.gbl...
Have you seen any NNTP classes that I may use or build upon to build a

simple newsreader/downloader?

Jim there is an NNTP demo included in IPWorks.
The NNTP component implements all of the protocol for you - leaving you
with a
very simple API to work with. If you need more sample code, let me know,
we've
got plenty.

Regards,
Lance R.
/n software
http://www.nsoftware.com/

-

Dec 13 '05 #6
Jim
To be fair to the nsoftware people, I downloaded the trial version of the
core components (Version 6.1.2161) to see for myself if they would be easy
to use.

I have to take back my doubts about the ease-of-use of the nsoftware nntp
component.

It is very easy to use AND intuitive. I made a test form, connected to my
NNTP server and downloaded the groups listing in less than 2
minutes...without having used nsoftware components before and without
reading any of the very detailed documentation that comes with the suite.

My hat is off to you sir. And, I offer my heartfelt apologies for having
lumped your company's products in with the rest. Yours by far outshines
anything I have used or tested to date.

Jim
"Jim" <re***@groups.please> wrote in message
news:b0******************@bignews6.bellsouth.net.. .
Thanks Lance, but this is for a freeware project. While I am certain that
your components are of impeccable quality and that they are very easy to
use, I cannot justify the $400 price tag for a freeware project.

With the .Net components that I have worked with thus far (and I have not
worked with IPWorks yet) I cringe at the very thought of spending more
than $100 on any component. The components that I have used this far miss
the marks of ease-of-use set by the COM components I was used to (pre-
this .Net disaster) by a mile.

They are neither intuitive nor easy to use. I will reserve judgment on
IPWorks until I have some extra time to play with a demo, but, to be quite
honest, if IPWorks is intuitive or as easy to use as the old COM
components that used extensively I would be shocked.

It is also a sad commentary on the devastation that Microsoft has wrought
throughout its own industry that the component developers didn't have
anything ready for .Net 2.0 at its launch. That means that they aren't
making enough money off of components to put the needed resources on the
projects that need upgrading for .Net 2.0. And, that means that the
masses of VB programmers that used to buy components like crack whores
needing a fix just aren't programming any more.

I suppose that's a major reason for the free Express editions of VS 2005.
Trying to get back what they scattered.

Alas, it may be too little, too late. As Microsoft is (and its component
developers are) learning.....it's damned hard to put Humpty back together
again.
"Lance R." <la****@nsoftware.removeme.com> wrote in message
news:OO**************@TK2MSFTNGP10.phx.gbl...
Have you seen any NNTP classes that I may use or build upon to build a

simple newsreader/downloader?

Jim there is an NNTP demo included in IPWorks.
The NNTP component implements all of the protocol for you - leaving you
with a
very simple API to work with. If you need more sample code, let me know,
we've
got plenty.

Regards,
Lance R.
/n software
http://www.nsoftware.com/

-


Dec 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mark | last post by:
I'm looking for a set of php scripts that can read an nntp server, pull all the posts from a newsgroup (text only, no images) and convert them to html pages. Perfect example is :...
2
by: Gary Stark | last post by:
Does anyone have such a beastie? I can't even get to first base. The following doesn't work ... $hostNNTP = "news.swiftdsl.com.au:119/nntp"; $nntp = imap_open( "{" . $hostNNTP ....
42
by: Steven O. | last post by:
I am seeking some kind of tool that I can use for GUI prototyping. I know how to use Visual Basic, but since a lot of software is being coded in Java or C++, I'd like to learn a Java or C++ -based...
6
by: Greg M | last post by:
I have 5 years of MS Access/VBA development experience and am moving into the VB.net world. I am seeking a tutor which could facilitate this move. I live in Anderson, IN and am willing to...
4
by: Jim | last post by:
Have you seen any NNTP classes that I may use or build upon to build a simple newsreader/downloader? Is there such a class in the .Net framework that I have overlooked? If not, inclusion of RFC...
11
by: Jim | last post by:
Have you seen any NNTP classes that I may use or build upon to build a simple newsreader/downloader? Is there such a class in the .Net framework that I have overlooked? If not, inclusion of RFC...
4
by: BiT | last post by:
Hi i'm trying to code simple nntp client with vb.net and sockets client class the problem is the machine keep stuck (probbley beacuse it ain't gettin` data from the server) after the user name...
15
by: Devon Null | last post by:
I was simply wondering if this was a mal-formed class header: #ifndef _items_h_ #define _items_h_ #include <iostream> #include <string> #include <vector> using namespace std;
7
by: Adrian | last post by:
What is a stringsteam supposed to do when you seek past the end of existing buffer. I can seek past the end of a file stream (my implementation fills the space will nulls but I cannot find if this...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.