GroupMemberConsole.cs :  » Network-Clients » GROF » grof » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Network Clients » GROF 
GROF » grof » GroupMemberConsole.cs
/*
 * Created by SharpDevelop.
 * User: magr2419
 * Date: 15.03.2006
 * Time: 12:13
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Threading;

using grof;

namespace grof{
  /// <summary>
  /// Description of GroupMemberConsole.
  /// </summary>
  public class GroupMemberConsole
  {
    private GroupMember member = null;
    private static readonly String[,] COMMANDS = { 
      { "help", "Lists all possible commands" },
      { "quit", "Quit the console application (group member leaves the group" }, 
      { "send <message>", "Sends a message to all group members" }, 
      { "getgm", "Lists all group members" }      
    };
        
    // TODO: doc
    public GroupMemberConsole( String groupName, String memberName,
                             String groupAddress, int groupPort, 
                            String listenerAddress, int listenerPort )
    {
      Debug.Listeners.Add( new TextWriterTraceListener( Console.Out ) );  
      Initializer init = new Initializer();
      init.GroupAddress = groupAddress;
      init.GroupName = groupName;
      init.GroupPort = groupPort;
      init.ListenerAddress = listenerAddress;
      init.ListenerPort = listenerPort;
      init.MemberName = memberName;
      
      this.member = new GroupMember( init );
            this.member.SetMessageReceiver(this.Received);
      this.member.JoinGroup();
      Thread.Sleep( 2000 );
      this.startConsole();
    }

        public void Received(Message msg)
        {
            Console.WriteLine("> received message: " + msg);
        }

    // group ernie 224.100.0.1 9050 127.0.0.1 9011
    public static void Main( string[] args )
    {
      if ( args.Length == 0 ||
          ( args.Length == 1 && args[0] == "help" ) )
      {
        
        Console.WriteLine( "Parameter:" );
        Console.WriteLine( "   group name       - The group name." );
        Console.WriteLine( "   member name      - The name of the group member." );        
        Console.WriteLine( "   group address    - The IP address of the multicast group." );
        Console.WriteLine( "   group port       - The port number of the multicast group." );
        Console.WriteLine( "   listener address - The IP address where the group member listens for TCP requests." );
        Console.WriteLine( "   listener port    - The port number where the group member listens fro TCP requests." );        
      } else if ( args.Length == 6 )
      {
        try 
        {
          int portNumber = Int32.Parse( args[3] );
          int listenerPort = Int32.Parse( args[5] );
          new GroupMemberConsole( args[0], args[1],
                                 args[2], portNumber, 
                                 args[4], listenerPort );
        } catch( Exception e )
        {
          Console.WriteLine( "!listener port/group port are not valid numbers! " + e.ToString() );
        }
      } else 
      {
        Console.WriteLine( "!wrong parameters!" );
      }                              
    }
  
    private void startConsole()
    {
      Console.WriteLine();
      Console.WriteLine();
      
      Console.WriteLine( "-----------------------------------------------------" );
      Console.WriteLine( "|                                                   |" );
      Console.WriteLine( "|              Group Member Console                 |" );
      Console.WriteLine( "|                                                   |" );
      Console.WriteLine( "-----------------------------------------------------" );
      Console.WriteLine();
      Console.Write( "> " );
      string input;    
      while ( !( input = Console.ReadLine() ).Equals( COMMANDS[1,0] ) )
      {
        string[] strs = input.Split( ' ' );
        switch( strs[0] )
        {
          // It is not possible to write here
          // case COMMANDS[2,0]
          case "send":
            if ( strs.Length == 2 )
            {
              this.member.Send( strs[1] );
            }
            break;          
          case "getgm":
            GroupMemberInfo[] gmInfos = this.member.GetGroupMembers();
            for ( int i=0; i<gmInfos.Length; i++ )
            {
              Console.WriteLine( "-> Group member #" + i + ": " + gmInfos[i].ToString() );
            }
            break;
          case "help":
            for ( int i=0; i<COMMANDS.Length/2; i++ )
            {
              Console.WriteLine( "-> " + COMMANDS[i,0] + " - " + COMMANDS[i,1] );
            }
            break;
          case "":
            Console.Write( "\n> " );
            break;          
          default:
            Console.WriteLine( "!command not valid!" );
            break;
        }
        Console.Write( "\n> " );                
      }      
      this.member.LeaveGroup();
      Console.WriteLine( "\nbye.\n\n" );
    }
  }
  
  
  
  
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.