Chat.Main C# (CSharp) Method

Main() public static method

public static Main ( string args ) : void
args string
return void
  public static void Main(string [] args ) 
  {

    LocalPort = SenderPort;
    RemotePort = ListenerPort;

    Usage();
    
    m_szHostName = Dns.GetHostName();
    m_LocalHost = Dns.GetHostByName(m_szHostName);

    Console.WriteLine("Local Port: {0}, Remote: {1}", LocalPort, RemotePort);
    Console.WriteLine("Initializing...");

    Initialize();

    Console.WriteLine("Starting Listener thread...");

    Thread workerThread = new Thread(new ThreadStart(Listener));
    workerThread.Start();

    byte [] buffer = null;

    Encoding ASCII = Encoding.ASCII;

    bool ShuttingDown = false;

    while(!ShuttingDown) 
    {
      string InputString = Console.ReadLine();

      if ( InputString.Length == 0 )
        continue;

      //Look for exit flag from user.
      if (InputString.StartsWith("@"))
      {
        lock(typeof(Chat))
        {
          m_Done = true;
          //
          // Send a terminator to ourselves,
          // so that the receiving thread can shut down.
          //
          InputString = m_szHostName + ":@";
        }//lock
        ShuttingDown = true;
      } 
      else 
      {
        lock(typeof(Chat))
        {
          InputString = m_szHostName + ":" + InputString;
        }//lock
      }//else

      buffer = new byte[InputString.Length + 1];
      //
      // send data to remote peer
      //

      int len = ASCII.GetBytes( InputString.ToCharArray(), 0, InputString.Length, buffer, 0);
      int ecode;
      lock(typeof(Chat))
      {
        ecode = m_Client.Send(buffer, len, m_RemoteEP);
      }//lock

      if(ecode <= 0) 
      {
        Console.WriteLine("Error in send : " + ecode);
      }//if

    }//while

    workerThread.Abort();
    workerThread.Join();

    Console.WriteLine("Closing connection...");
    Terminate();

  } // Main