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");
        }

    }

}
}           

Hi Venkatech 3, welcome at DaniWeb.
I'm affraid, without specific error messages, we can do little to help you.

There should be many errors.. It seems like a copy and paste.

simple errors in your code i can see

Lines 32, 43 .SubString Should be .Substring which is odd seeing as it's fine on line 21

Like ddanbe said we can't really help you without specific errors. And maybe some insight as to what your application does exactly.

namespace is a block statement, which means it only operates on the next line, or on anything within the {} that define the block.

You don't have {} around your code for the namespace.

commented: View of a pro! +14

Your namespace should match with the name of your C# project name.
Is "venkat" your project name and if not try changing "venkat" to the name of your project (not the solution).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.