1: using System;
     2: using System.Runtime.Remoting;
     3: using System.Runtime.Remoting.Channels;
     4: using System.Runtime.Remoting.Channels.Http;
     5: 
     6: public class ChatClient : MarshalByRefObject
     7: {
     8:     private string username = null;
     9:     public override object InitializeLifetimeService()
    10:     {
    11:         return null;
    12:     }
    13:     public ChatClient(string alias)
    14:     {
    15:         this.username = alias;
    16:     }
    17:     public void Run()
    18:     {
    19:         RemotingConfiguration.Configure("Client.config");
    20:         ChatCoordinator chatcenter = new ChatCoordinator();
    21:         chatcenter.Submission += new 
    22:             SubmissionEventHandler(this.SubmissionReceiver);
    23:         String keyState = "";
    24:         while (true)
    25:         {
    26:             Console.WriteLine("Press 0 (zero) and ENTER to Exit:\n\r");
    27:             keyState = Console.ReadLine();
    28:             if(String.Compare(keyState,"0",true)==0)
    29:                 break;
    30:             chatcenter.Submit(keyState, username);
    31:         }
    32:         chatcenter.Submission -= new SubmissionEventHandler(this.SubmissionReceiver);
    33:     }
    34:     
    35:     public void SubmissionReceiver(object sender, SubmitEventArgs args)
    36:     {
    37:         if(String.Compare(args.Contributor,username,true)==0)
    38:         {
    39:             Console.WriteLine("Your message was broadcast.");   
    40:         }
    41:         else
    42:         {
    43:             Console.WriteLine(args.Contributor
    44:                 + "says: " + args.Contribution);
    45:         }
    46:     }
    47:     
    48:     public static void Main(string[] Args)
    49:     {
    50:         if(Args.Length != 1)
    51:         {
    52:             Console.WriteLine("You need to type an alias.");
    53:             return;
    54:         }
    55:         ChatClient client = new ChatClient(Args[0]);
    56:         client.Run();
    57:     }
    58: }
    59: