예제 #1
0
        public void TestServerCmppSendSmsSimple()
        {
            var client = new CmppSmsClient(_configurations);

            var server = new CmppSmsServer(new SmsServerConfigurations()
            {
                HostName  = _configurations.HostName,
                HostPort  = _configurations.HostPort,
                UserName  = _configurations.UserName,
                Password  = _configurations.UserName,
                ServiceID = _configurations.ServiceId,
            });


            var ts1 = server.StartAsync();

            ts1.Wait();


            var receivers = new string[] { "18613350979" };
            var content   = "【测试短信】测试短信";

            var cancel = new CancellationTokenSource();

            client.SmsResponseReceived += (sender, e) =>
            {
                var response = e.Envolope.Response as CmppMessageSubmitResponse;
                Debug.WriteLine("<!>RESPONSE: {0}", response.Result);
            };

            client.SmsReportReceived += (sender, e) =>
            {
                var report = e.Report as CmppMessageReport;
                Debug.WriteLine("<!>REPORT: {0}", report.Stat);
                cancel.Cancel();
            };

            Task.Run(async() =>
            {
                //await client.StartAsync();
                await client.SendSmsAsync(receivers, content);

                await Task.Delay(5000, cancel.Token);

                await client.StopAsync();
            }).Wait();

            var ts2 = server.StopAsync();

            ts2.Wait();
        }
예제 #2
0
        public void TestServerCmppSendSmsPerformanceByTime()
        {
            var client = new CmppSmsClient(_configurations);

            var server = new CmppSmsServer(new SmsServerConfigurations()
            {
                HostName  = _configurations.HostName,
                HostPort  = _configurations.HostPort,
                UserName  = _configurations.UserName,
                Password  = _configurations.UserName,
                ServiceID = _configurations.ServiceId,
            });


            var ts1 = server.StartAsync();

            ts1.Wait();


            var receivers = new string[] { "13979121569" };
            var content   = "测试短信";

            var totalSpan = TimeSpan.FromMinutes(5);
            int count     = 0;

            int responseCount = 0;
            int reportCount   = 0;

            Task.Run(async() =>
            {
                client.SmsResponseReceived += (sender, e) =>
                {
                    responseCount++;
                };

                client.SmsReportReceived += (sender, e) =>
                {
                    reportCount++;
                };

                await client.StartAsync();

                var start = DateTime.Now;
                DateTime?responseComplete = null;
                DateTime?reportComplete   = null;

                var updateStamp = DateTime.Now;

                while ((DateTime.Now - start) < totalSpan)
                {
                    await client.SendSmsAsync(receivers, content);
                    count++;
                    await Task.Delay(0);

                    if ((DateTime.Now - updateStamp) >= TimeSpan.FromMinutes(1))
                    {
                        updateStamp = DateTime.Now;
                        Debug.WriteLine("{0} {1} {2} ", count, responseCount, reportCount);
                    }
                }

                var waitSpan  = TimeSpan.FromSeconds(count / 100);
                var waitStart = DateTime.Now;

                while ((DateTime.Now - waitStart) < waitSpan)
                {
                    if ((DateTime.Now - updateStamp) >= TimeSpan.FromMinutes(1))
                    {
                        updateStamp = DateTime.Now;
                        Debug.WriteLine("{0} {1} {2} ", count, responseCount, reportCount);
                    }

                    if (responseComplete == null && responseCount == count)
                    {
                        responseComplete = DateTime.Now;
                    }

                    if (reportComplete == null && reportCount == count)
                    {
                        reportComplete = DateTime.Now;
                    }

                    if (responseCount == count && reportCount == count)
                    {
                        break;
                    }
                    await Task.Delay(50);
                }

                await client.StopAsync();


                Debug.WriteLine("Messages Sent {0}", count);
                Debug.WriteLine("Rsponses {0}", responseCount);
                Debug.WriteLine("Reports  {0}", reportCount);

                if (responseComplete.HasValue)
                {
                    var duration = (responseComplete.Value - start).TotalSeconds;
                    Debug.WriteLine("Submit spent {0} seconds on {1} messages, throughput : {2} mps",
                                    duration, count, count / duration);
                }

                if (reportComplete.HasValue)
                {
                    var duration = (reportComplete.Value - start).TotalSeconds;
                    Debug.WriteLine("Report spent {0} seconds on {1} messages, throughput : {2} mps",
                                    duration, count, count / duration);
                }
            }).Wait();

            var ts2 = server.StopAsync();

            ts2.Wait();

            var stats = server.GetStats();

            Debug.WriteLine("Server stats:\r\n");
            Debug.WriteLine(stats);
        }