The first method of our Nntp
client class is the Connect
method. This method takes a server name that represents the remote NNTP server that will service our requests.
public void Connect(string server)
{
string response;
Connect(server, 119);
response = Response();
if (response.Substring(0, 3) != "200")
{
throw new NntpException(response);
}
}
We call the Connect
method of our base TcpClient
class with the server name and port 119. Port 119 is the well-known port for NNTP servers. The server should respond with a status-code indicating that connection was successful. When you are finished calling methods to the Nntp client object, then you should call the Disconnect
method to terminate the connection.
public void Disconnect()
{
string message;
string response;
message = "QUIT\r\n";
Write(message);
response = Response();
if (response.Substring(0, 3) != "205")
{
throw new NntpException(response);
}
}
The method will send a QUIT
message to the server and the server should respond with a 205 status-code indicating that the it is disconnecting the socket.
When you first instantiate the Nntp
object you should call the Connect
method and when you are finished you should call the Disconnect
method. In between, you can call three method, GetNewsgroups
, GetNews
and Post
, to receive and send news to the NNTP server.
Comments