ckjie 0 Newbie Poster

Hi all, i am doing a chat server project, i get the code below from a book.
but when i try to compile it, i get the errors below, can anyone tell me y i get such error or how to solve it?
or maybe this code is for c#2005 because the book was written in 2005?
i compiled this code with visual studio 2008, c#, console program.
thx lots!!!

private void ReceiveChat()
{
bool keepalive=true;
while(keepalive)
{
try
{
Byte[] buffer=new Byte[2084];
ns.Read(buffer,0,buffer.Length);
string chatter=System.Text.Encoding.ASCII.GetString(buffer);
string[] tokens=chatter.Split(new Chat[]{'|'});

if(tokens[0]=="CHAT")
{
rtbChatIn.AppendText(tokens[1]);
if(logging)
logwriter.WriteLine(tokens[1]);
}

if(tokens[0]=="PRIV"){
rtbChatIn.AppendText("Private from ");
rtbChatIn.AppendText(tokens[1].Trim() );
rtbChatIn.AppendText(tokens[2]+"\r\n");
if(logging){
logwriter.Write("Private from ");
logwriter.Write(tokens[1].Trim() );
logwriter.WriteLine(tokens[2]+"\r\n");
}
}

if(tokens[0] == "JOIN")
{
rtbChatIn.AppendText(tokens[1].Trim()  );
rbChatIn.AppendText(" has joined the Chat\r\n");
if(logging)
logwriter.WriteLine(tokens[1]+" has joined the Chat");
string newguy = tokens[1].Trim(new char[]{'\r','\n'});
1bChatters.Items.Add(newguy);
}
if (tokens[0] == "GONE")
{
rtbChatIn.AppendText(tokens[1].Trim() );
rtbChatIn.AppendText(" has left the Chat\r\n");
if(logging)
logwriter.WriteLine(tokens[1]+" has left the Chat");
1bChatters.Items.Remove(tokens[1].Trim(new char[]{'\r','\n'}));
}

if (tokens[0] =="QUIT")
{
ns.Close();
clientsocket.Close();
keepalive = false;
statusBar1.Text = "Server has stopped";
connected= false;
btnSend.Enabled = false;
benDisconnect.Enabled = false;
}
}
catch)Exception e){}
}
}

My Documents\Visual Studio 2008\Projects\client1\client1\ReceiveChat.cs(1,9): error CS1518: Expected class, delegate, enum, interface, or struct
My Documents\Visual Studio 2008\Projects\client1\client1\ReceiveChat.cs(8,6): error CS1001: Identifier expected
My Documents\Visual Studio 2008\Projects\client1\client1\ReceiveChat.cs(8,8): error CS1518: Expected class, delegate, enum, interface, or struct
My Documents\Visual Studio 2008\Projects\client1\client1\ReceiveChat.cs(8,19): error CS1518: Expected class, delegate, enum, interface, or struct
My Documents\Visual Studio 2008\Projects\client1\client1\ReceiveChat.cs(8,24): error CS1001: Identifier expected
My Documents\Visual Studio 2008\Projects\client1\client1\ReceiveChat.cs(11,8): error CS1001: Identifier expected
My Documents\Visual Studio 2008\Projects\client1\client1\ReceiveChat.cs(11,10): error CS1518: Expected class, delegate, enum, interface, or struct
My Documents\Visual Studio 2008\Projects\client1\client1\ReceiveChat.cs(11,35): error CS1518: Expected class, delegate, enum, interface, or struct
My Documents\Visual Studio 2008\Projects\client1\client1\ReceiveChat.cs(11,40): error CS1001: Identifier expected
My Documents\Visual Studio 2008\Projects\client1\client1\ReceiveChat.cs(11,41): error CS1518: Expected class, delegate, enum, interface, or struct
My Documents\Visual Studio 2008\Projects\client1\client1\ReceiveChat.cs(11,45): error CS1022: Type or namespace definition, or end-of-file expected