when i compile the below code, it throws me error messages like the namespace does not exist in the current context.. i dont know where is the problem.. pls correct my errors. thanks in advance.
using System;
using System.Collections;
using System.Net.Sockets;
namespace venkat
public class Nntp : System.Net.Sockets.TcpClient
{
string message;
string response;
ArrayList retval=new ArrayList();
public void Connect(string server)
{
Connect(server,119);
response=Response();
if(response.Substring(0,3)!="200")
{
Console.WriteLine("\n Exception:",response);
}
}
public void DisConnect(string server)
{
message="QUIT\r\n";
response=Write(message);
if(response.SubString(0,3)!="205")
{
Console.WriteLine("\n Exception:",response);
}
}
public ArrayList GetNewsgroups()
{
retval=new ArrayList();
message="LIST\r\n";
Write(message);
if(response.SubString(0,3)!="215")
{
Console.WriteLine("\n Exception:",response);
}
while(true)
{
response=Response();
if(response==".\r\n" || response==".\n")
{
return retvalue;
}
else
{
char[] separator={' '};
string[] values=response.Split(separator);
retvalue.add(values[0]);
continue;
}
}
}
public ArrayList Getnews()
{
retval = new ArrayList();
message = "GROUP " + newsgroup + "\r\n";
Write(message);
response = Response();
if (response.Substring( 0, 3) != "211")
{
Console.WriteLine("\n Exception:",response);
}
char[] separator = { ' ' };
string[] values = response.Split(separator);
long start = Int32.Parse(values[2]);
long end = Int32.Parse(values[3]);
if (start+100 < end && end > 100)
{
start = end-100;
}
for (long i=start;i<end;i++)
{
message = "ARTICLE " + i + "\r\n";
Write(message);
response = Response();
if (response.Substring( 0, 3) == "423")
{
continue;
}
if (response.Substring( 0, 3) != "220")
{
Console.WriteLine("\n Exception:",response);
}
string article = "";
while (true)
{
response = Response();
if (response == ".\r\n")
{
break;
}
if (response == ".\n")
{
break;
}
if (article.Length < 1024)
{
article += response;
}
}
retval.Add(article);
}
return retval;
}
public void Post(string newsgroup, string subject, string from,string content)
{
message = "POST " + newsgroup + "\r\n";
Write(message);
response = Response();
if (response.Substring( 0, 3) != "340")
{
Console.WriteLine("\n Exception:",response);
}
message = "From: " + from + "\r\n" + "Newsgroups: " + newsgroup + "\r\n" + "Subject: " + subject + "\r\n\r\n" + content + "\r\n.\r\n";
Write(message);
response = Response();
if (response.Substring( 0, 3) != "240")
{
Console.WriteLine("\n Exception:",response);
}
}
private void Write(string message)
{
System.Text.ASCIIEncoding en = new System.Text.ASCIIEncoding() ;
byte[] WriteBuffer = new byte[1024] ;
WriteBuffer = en.GetBytes(message) ;
NetworkStream stream = GetStream() ;
stream.Write(WriteBuffer,0,WriteBuffer.Length);
}
private string Response()
{
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
byte []serverbuff = new Byte[1024];
NetworkStream stream = GetStream();
int count = 0;
while (true)
{
byte []buff = new Byte[2];
int bytes = stream.Read( buff, 0, 1 );
if (bytes == 1)
{
serverbuff[count] = buff[0];
count++;
if (buff[0] == '\n')
{
break;
}
}
else
{
break;
};
};
string retval = enc.GetString( serverbuff, 0, count );
return retval;
}
public static void Main(string[] args)
{
try
{
Nntp obj = new Nntp();
obj.Connect("news.microsoft.com");
System.Collections.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","venkatesh6911@gmail.com (venkatesh jaisankar)", "Goodbye");
obj.Disconnect();
}
catch (Exception)
{
System.Console.WriteLine("unhandled exception");
}
}
}
}