Ejemplo n.º 1
0
        public static new ListenConfigModel GetDefaults()
        {
            var baseDefaults = BaseConfigModel.GetDefaults();
            var defaults     = baseDefaults.Clone <ListenConfigModel>();

            defaults.endPoint = baseDefaults.endPoint;
            defaults.backLog  = 100;
            return(defaults);
        }
Ejemplo n.º 2
0
        static async Task <int> Main(string[] args)
        {
            int maxClientCount = 1;
            int messageCount   = 8;

            var connectionConfig = BaseConfigModel.GetDefaults();
            var identityProvider = UserProvider.GetDefaults(maxClientCount);

            // Run multiple clients async
            int currentClientCount = 0;
            var tasks = new int[maxClientCount]
                        .Select(x => Task.Run <int>(async() =>
            {
                var identity = identityProvider.AuthIdentities.ElementAt(currentClientCount);
                var client   = new ClientWrapper(connectionConfig, identity, messageCount);
                ++currentClientCount;
                try
                {
                    await client.Connect();
                }
                catch (Exception e)
                {
                    SocketObject.GlobalLog(e.ToString());
                    return(-1);
                }

                return(client.isSuccess ? 0 : 1);
            }))
                        .ToList();
            await Task.WhenAll(tasks.ToArray());

            // Evaluate all clients
            var failureCount = tasks.Count(x => x.Result != 0);

            SocketObject.GlobalLog($"Client failures: {failureCount}");
            return(failureCount > 0 ? 1 : 0);
        }