static void Main(string[] args)
        {
            try
            {
                int iterations = 25000;
                int clientCount = 40;
                int messageSize = 1024 * 1;
                var data = new byte[messageSize];
                var message = BuildMessage(data);

                var action = new Action<SocketClient>((client) =>
                {
                    for (var i = 0; i < iterations; i++)
                    {
                        client.Send(message);
                    }
                });

                for (var index = 0; index < clientCount; index++)
                {
                    var client = new SocketClient(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9900));
                    client.Connect();
                    Task.Factory.StartNew(() => action(client));
                }

                Console.WriteLine("Press any key to terminate the client process...");
                Console.Read();
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR: " + ex.Message);
                Console.Read();
            }
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            try
            {
                String host = args[0];
                Int32 port = Convert.ToInt32(args[1]);
                Int16 iterations = 1;
                if (args.Length == 3)
                {
                    iterations = Convert.ToInt16(args[2]);
                }

                using (SocketClient sa = new SocketClient(host, port))
                {
                    sa.Connect();

                    for (Int32 i = 0; i < iterations; i++)
                    {
                        Console.WriteLine(sa.SendReceive("Message #" + i.ToString()));
                    }
                    sa.Disconnect();

                    Console.WriteLine("Press any key to terminate the client process...");
                    Console.Read();
                }
            }
            catch (IndexOutOfRangeException)
            {
                Console.WriteLine("Usage: SocketAsyncClient <host> <port> [iterations]");
            }
            catch (FormatException)
            {
                Console.WriteLine("Usage: SocketAsyncClient <host> <port> [iterations]." +
                    "\r\n\t<host> Name of the host to connect." +
                    "\r\n\t<port> Numeric value for the host listening TCP port." +
                    "\r\n\t[iterations] Number of iterations to the host.");
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR: " + ex.Message);
            }
        }
Beispiel #3
0
        //____________________________________________________________________________
        static void HandleConsoleInteraction(ConfigFileHandler configHandler, SocketClient socketClient)
        {
            string stringToCompare = "";
            string theEntry        = "";
            Int32  count           = 0;

            // Let's put a little wait here to let the clients finish, so that we
            // will not write irrelevant info to Console if it finishes fast.
            Thread.Sleep(1000);

            while (stringToCompare != closeString)
            {
                if (socketClient.finished == true)
                {
                    if ((count > 0) && (socketClient.abortTest == false))
                    {
                        Console.WriteLine("\r\n\r\n*********   " + Program.completedString + "   *********\r\nTo close the program and write log, type '" + Program.closeString + "' and press Enter");
                    }
                }
                else
                {
                    if (watchProgramFlow == true)
                    {
                        Console.WriteLine(wpfTrueString);
                    }
                    else
                    {
                        Console.WriteLine(wpfFalseString);
                    }
                }

                theEntry = Console.ReadLine().ToUpper(CultureInfo.InvariantCulture);

                switch (theEntry)
                {
                case checkString:
                    GetPercentageCompleted(configHandler, socketClient);
                    break;

                case wpf:
                    if ((Program.watchProgramFlow == false) && (socketClient.finished == false))
                    {
                        Program.watchProgramFlow = true;
                        Console.WriteLine("Changed watchProgramFlow to true.");
                        Program.testWriter.WriteLine("\r\nStart logging program flow.\r\n");
                    }
                    else
                    {
                        Console.WriteLine("Program flow was already being logged.");
                    }

                    break;

                case wpfNo:
                    if ((Program.watchProgramFlow == true) && (socketClient.finished == false))
                    {
                        Program.watchProgramFlow = false;
                        Console.WriteLine("Changed watchProgramFlow to false.");
                        Program.testWriter.WriteLine("\r\nStopped logging program flow.\r\n");
                    }
                    else
                    {
                        Console.WriteLine("Program flow was already NOT being logged.");
                    }
                    break;

                case stopString:
                    if (socketClient.finished == false)
                    {
                        socketClient.abortTest = true;
                        Console.WriteLine("test stopped");
                        stringToCompare = closeString;
                    }
                    break;

                case closeString:
                    stringToCompare = closeString;
                    break;

                default:
                    Console.WriteLine("Unrecognized entry");
                    break;
                }
                count++;
            }
            CloseProgram(configHandler, socketClient);
        }