Network C# Tutorial

using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
class MainClass
{
   public static void Main()
   {
      int receivedDataLength;
      byte[] data = new byte[1024];
      TcpListener socket = new TcpListener(9999);
      socket.Start();
      TcpClient client = socket.AcceptTcpClient();
      NetworkStream ns = client.GetStream();
      string welcome = "Welcome";
      data = Encoding.ASCII.GetBytes(welcome);
      ns.Write(data, 0, data.Length);
      while(true)
      {
         data = new byte[1024];
         receivedDataLength = ns.Read(data, 0, data.Length);
         Console.WriteLine(Encoding.ASCII.GetString(data, 0, receivedDataLength));
         ns.Write(data, 0, receivedDataLength);
      }
      ns.Close();
      client.Close();
      socket.Stop();
   }
}