TNewsServer implements an NNTP (Network News Transfer Protocol) news server on port 119. It is built on TSocket and uses DBF/CDX files to store newsgroups and articles. TNewsInstance handles each connected client session, parsing NNTP commands and serving article data.
TNewsServer
Key DATA Members
DATA
Type
Description
oTimer
Object
Timer for periodic client task processing
oSocket
Object
Listener socket bound to port 119
aInstances
Array
Array of TNewsInstance objects for active clients
cDefPath
Character
Default data directory for DBF/CDX files
lDebug
Logical
Enable debug logging to cLogFile
Methods
Method
Description
New( oWnd, cPath )
Create server; creates Groups.dbf and indexes in cPath
Activate()
Start listening on port 119 for incoming connections
End()
Stop timer, close socket, and terminate all client instances
TNewsInstance
Key DATA Members
DATA
Type
Description
oSocket
Object
Client socket for this NNTP session
oServer
Object
Parent TNewsServer reference
cGroup
Character
Currently selected newsgroup name
lPostAllow
Logical
Whether posting is allowed
NNTP Commands Implemented
Method
NNTP Command
Description
Article()
ARTICLE
Retrieve article head and/or body
Head()
HEAD
Retrieve article header only
Body()
BODY
Retrieve article body only
Group()
GROUP
Select a newsgroup
List()
LIST
List available newsgroups
ListGroup()
LISTGROUP
List article numbers in current group
Post()
POST
Begin posting a new article
Quit()
QUIT
End the NNTP session
NewGroups()
NEWGROUPS
List groups created since a date/time
XOver()
XOVER
Overview of articles (subject, author, date, etc.)
Stat()
STAT
Check if article exists without retrieving it
Example: Start News Server
#include "FiveWin.ch"
function Main()
local oWnd, oServer
DEFINE WINDOW oWnd TITLE "NNTP News Server" SIZE 600, 400
oServer := TNewsServer():New( oWnd, "c:\newsserver\data" )
oServer:Activate()
ACTIVATE WINDOW oWnd CENTERED
return nil
Notes
The server listens on TCP port 119 (standard NNTP port). Each client connection creates a TNewsInstance.
Newsgroups and articles are stored in DBF files with CDX indexes, organized by group ID.
The timer (10ms interval) processes pending client tasks (e.g., sending LIST results in chunks).
Command parsing is case-insensitive. Unrecognized commands receive "500 Command not implemented."