Brunet.EdgeTester.Main C# (CSharp) Method

Main() public static method

public static Main ( string args ) : void
args string
return void
    public static void Main(string[] args)
    {
      if (args.Length < 3) {
        Console.WriteLine("Usage: edgetester.exe " +
                          "[client|server] [tcp|udp|function] port " +
                          "localhost|qubit|cantor|starsky|behnam|kupka)");
        return;
      }

      if( args.Length >= 5) {
        delay = Int32.Parse(args[4]);
      }

      EdgeFactory ef = new EdgeFactory();
      int port = System.Int16.Parse(args[2]);

      _threads = ArrayList.Synchronized(new ArrayList());
      EdgeListener el = null;
      if( args[1] == "function" ) {
        //This is a special case, it only works in one thread
        el = new FunctionEdgeListener(port);
        el.EdgeEvent += new EventHandler(HandleEdge);
        //Start listening:
        el.Start();
        ef.AddListener(el);
        el.CreateEdgeTo(
         TransportAddressFactory.CreateInstance("brunet.function://localhost:" + port),
          ClientLoop);
      }
      else if (args[0] == "server") {
        if (args[1] == "tcp") {
          el = new TcpEdgeListener(port);
        }
        else if (args[1] == "udp") {
          el = new UdpEdgeListener(port);
        }
        else {
          el = null;
        }
        el.EdgeEvent += new EventHandler(HandleEdge);
//Start listening:
        el.Start();
        _el = el;
        Console.WriteLine("Press Q to quit");
        Console.ReadLine();
        el.Stop();
      }
      else if (args[0] == "client") {
        TransportAddress ta = null;
        if (args[1] == "tcp") {
          el = new TcpEdgeListener(port + 1);
        }
        else if (args[1] == "udp") {
          el = new UdpEdgeListener(port + 1);
        }
        else {
          el = null;
        }
        ef.AddListener(el);
        _el = el;
        string uri = "brunet." + args[1] + "://" + NameToIP(args[3]) + ":" + port;
        ta = TransportAddressFactory.CreateInstance(uri);
        System.Console.WriteLine("Making edge to {0}\n", ta.ToString());
        el.Start();
        ef.CreateEdgeTo(ta, ClientLoop);
      }
    }