예제 #1
0
 public SpeedTestClient(TcpIpSystem system, IPAddress ip, int port, int numConnection, int timespan, SpeedTestModeFlag mode, CancellationToken cancel = default)
 {
     this.System        = system;
     this.ServerIP      = ip;
     this.ServerPort    = port;
     this.Cancel        = cancel;
     this.NumConnection = Math.Max(numConnection, 1);
     this.TimeSpan      = Math.Max(timespan, 1000);
     this.Mode          = mode;
     if (Mode == SpeedTestModeFlag.Both)
     {
         this.NumConnection = Math.Max(NumConnection, 2);
     }
     this.ClientStartEvent = new AsyncManualResetEvent();
     InitSendData();
 }
예제 #2
0
        static public async Task <List <SpeedTestClient.Result> > RunSpeedTestWithMultiTryAsync(TcpIpSystem system, IPAddress ip, int port, int numConnection, int timespan, SpeedTestModeFlag mode, int numTry, int interval, CancellationToken cancel = default)
        {
            List <SpeedTestClient.Result> ret = new List <Result>();

            numTry = Math.Max(numTry, 1);

            for (int i = 0; i < numTry; i++)
            {
                if (cancel.IsCancellationRequested)
                {
                    return(new List <Result>());
                }

                SpeedTestClient tc = new SpeedTestClient(system, ip, port, numConnection, timespan, mode, cancel);

                var result = await tc.RunClientAsync();

                if (result != null)
                {
                    ret.Add(result);
                }

                await cancel._WaitUntilCanceledAsync(Util.GenRandInterval(interval));
            }

            return(ret);
        }