Network C# Tutorial

using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
class MainClass
{
    public static void Main() 
    {
        TcpListener listener = new TcpListener(IPAddress.Parse("127.0.0.1"), 8000);
        Console.WriteLine("About to initialize port.");
        listener.Start();
        Console.WriteLine("Listening for a connection...");
            
        try 
        {
            using (TcpClient client = listener.AcceptTcpClient())
            {
                Console.WriteLine("Connection accepted.");
                NetworkStream stream = client.GetStream();
                using (BinaryWriter w = new BinaryWriter(stream))
                {
                }
                using (BinaryReader r = new BinaryReader(stream))
                {
                }
            }
        } 
        catch (Exception ex) 
        {
            Console.WriteLine(ex.ToString());
        }
        finally
        {
            listener.Stop();
            Console.WriteLine("Listener stopped.");
        }
   }
}