private static void StartServer(ConnectArgs arguments) { var server = new SocketServer(arguments.Port); var connectionCount = 0; var messageCount = 0; server.Listener.OnAccept().Subscribe((s) => { Interlocked.Increment(ref connectionCount); s.OnMessage().Subscribe((d) => Interlocked.Increment(ref messageCount)); }); Observable.Interval(TimeSpan.FromSeconds(5)).TimeInterval() .Subscribe(_ => { var rate = Interlocked.Exchange(ref messageCount, 0) / 5.0; var current = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Green; Console.Write("server: Active: "); Console.Write(connectionCount); Console.Write("\tMsg/sec: "); Console.WriteLine(rate); Console.ForegroundColor = current; }); }
public static TestScenario Create(ConnectArgs commandline) { string scenario = commandline.Scenario; if (string.IsNullOrEmpty(scenario)) { throw new ArgumentNullException("scenario"); } var scenarios = Assembly.GetExecutingAssembly() .GetTypes() .Where(t => typeof(TestScenario).IsAssignableFrom(t) && t != typeof(TestScenario) && t.IsClass) .ToArray(); var type = scenarios.FirstOrDefault(t => t.Name.EndsWith(scenario, true, CultureInfo.InvariantCulture)); if (type == null) { Console.WriteLine("Scenario {0} not found.", scenario); Console.WriteLine("Available scenarios: \n"); foreach (var name in scenarios) { Console.WriteLine("\t" + name.Name); } return(null); } Console.WriteLine("Executing scenario:" + type.Name); var instance = (TestScenario)Activator.CreateInstance(type); instance.ConnectArguments = commandline; return(instance); }
public static TestScenario Create(ConnectArgs commandline) { string scenario = commandline.Scenario; if (string.IsNullOrEmpty(scenario)) { throw new ArgumentNullException("scenario"); } var scenarios = Assembly.GetExecutingAssembly() .GetTypes() .Where(t => typeof(TestScenario).IsAssignableFrom(t) && t != typeof(TestScenario) && t.IsClass) .ToArray(); var type = scenarios.FirstOrDefault(t => t.Name.EndsWith(scenario, true, CultureInfo.InvariantCulture)); if (type == null) { Console.WriteLine("Scenario {0} not found.", scenario); Console.WriteLine("Available scenarios: \n"); foreach (var name in scenarios) { Console.WriteLine("\t" + name.Name); } return null; } Console.WriteLine("Executing scenario:" + type.Name); var instance = (TestScenario)Activator.CreateInstance(type); instance.ConnectArguments = commandline; return instance; }
public static bool IsServer(this ConnectArgs args) { return(String.Compare("server", args.Mode, true, CultureInfo.InvariantCulture) == 0); }
public static string CreateNetTcpAddress(this ConnectArgs args) { return("net.tcp://" + args.Server + ":" + args.Port); }
public ClientManager(ConnectArgs arguments) { this.arguments = arguments; }