///
/// Yo !!
/// Chat program using .net remoting
/// developed using C# and the .NET Framework.
/// 
/// author: J Edvar 
/// 
/// URL: http://www.superedge.com 
/// email: edvarp@yahoo.com
///
/// Remarks: csc /debug+ /r:YoServer.EXE /r:system.runtime.remoting.dll 
YoClient.cs
///
/// History
/// feb-25-2003	Developed the first tests 
///
///
///



using System;

// Import the Remoting API support
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;

// Use the Yo!Server namespace
using YoServer;

namespace YoClient 
{
  /// <summary>
  /// This is the Yo! Client. The client side in this .net remoting 
project
  /// the connection is made using a port number like YoClient 1000
  /// DevNote: Please remember that if you are using VS.NET you got to
  /// associate the system.remoting.dll manually, probably. 
  /// So, FIRST compile the server, SECOND include the server namespace 
created
  /// into the client, THIRD associate the system.remoting.dll into the 
project
  /// for the intelissense as well AND FINALLY compile the client
  /// </summary>

  class TYoClient
  {

    static void Main(string[] args)
    {

      if (args.Length < 1) 
      {
        Console.WriteLine( "Incorrect parameters:  \tUsage: edgeClient 
portNumber" );
        Console.WriteLine( "\t e.g., edgeClient 1000" ); 
        // get out the program
        return;
      }

      int listeningChannel = Int32.Parse( args [0] );
      // Create and register a channel to communicate to the server
      // Later, get more info about channels with Wagner and over the 
net
      // The Yo!Client will use the port passed in as args to listen 
for callbacks
      HttpChannel channel = new HttpChannel( listeningChannel );
      // Check why needs to register
      ChannelServices.RegisterChannel( channel );

      // Create an instance on the remote server and call a method 
remotely
      TYoServer yoClient = (TYoServer) Activator.GetObject( typeof ( 
TYoServer), "http://localhost:1099/YoServer");

      if (yoClient == null) 
      {
        Console.WriteLine( "Unable to retrieve info from Yo! Server..." 
);
        return;
      }

      // Create a unique Client ID
      string clientID = Guid.NewGuid().ToString();
      string message = "Yo!!: "+clientID+", has joined the session at 
port #"+listeningChannel;

      // Invoke a method from the Server and display the returned value
      Console.WriteLine(yoClient.displayMessage( clientID, message ) );

      while (message.ToLower().StartsWith( "hasta!" ) == false) 
      {
        Console.WriteLine( "Type a message or 'hasta!' to disconnect" 
);
        message = Console.ReadLine();
        yoClient.addMessage( clientID, message );
      }
      Console.WriteLine( "The Messages Are:" + 
yoClient.retrieveAllMessages( clientID ) );
//      yoClient.displayMessage( clientID, ""Yo! Hasta la vista "+ 
clientID +" !!! ");
//      yoClient.displayMessage( clientID, clientID +" has left the 
session at port#"+listeningChannel,"... Terminating..." );

    }

  }
}

