public void TestLifetimeServer() { SmsServerConfigurations configs1 = new SmsServerConfigurations() { HostName = "127.0.0.1", HostPort = 12321, UserName = "******", Password = "******", ServiceID = "99999" }; SgipConfigurations configs2 = new SgipConfigurations() { HostName = configs1.HostName, HostPort = configs1.HostPort, UserName = configs1.UserName, Password = configs1.Password, ServiceId = configs1.ServiceID }; InternalSgipSmsServer server = new InternalSgipSmsServer(configs1); SgipSmsClient client = new SgipSmsClient(configs2); var t1 = server.StartAsync(); t1.Wait(); var t2 = client.StartAsync(); t2.Wait(); bool isConnected = (client.Status == SmsClientStatus.Connected); Debug.WriteLine("Waiting..."); var tw = Task.Delay(10000); tw.Wait(); var t11 = client.StopAsync(); t11.Wait(); var t12 = server.StopAsync(); t12.Wait(); Assert.IsTrue(isConnected); }
private static void TestSgipChannel() { var configs = new SgipConfigurations() { HostName = "127.0.0.1", ListenHostName = "127.0.0.1", HostPort = 8801, ListenPort = 8802, UserName = "******", Password = "******", ServiceId = "3010099999", CorporationId = "99999", KeepConnection = false }; //configs = new SgipConfigurations() //{ // HostName = "220.201.8.97", // HostPort = 9001, // ListenPort = 8822, // UserName = "******", // Password = "******", // ServiceId = "10655024033", // CorporationId = "31850", // ServiceType="9991800181", // KeepConnection = false, //}; var receiver = Program.GetArgumentValue("no"); var content = Program.GetArgumentValue("text"); if (string.IsNullOrEmpty(receiver)) { receiver = "18613350979"; } if (string.IsNullOrEmpty(content)) { content = "【天天快递】明天下雨,请记得带伞。"; } Console.WriteLine("sending \"{0}\" to {1}...", content, receiver); var t = Task.Run(async() => { var client = new SgipSmsClient(configs); await client.StartAsync(); client.SmsResponseReceived += (sender, e) => { var response = e.Envolope.Response as SgipMessageSubmitResponse; Console.WriteLine("<!> RESPONSE: " + response.Result.ToString()); }; client.SmsReportReceived += (sender, e) => { var report = e.Report as SgipMessageReport; Console.WriteLine("<!> REPORT: " + report.State.ToString()); }; await client.SendSmsAsync(receiver, content); }); try { t.Wait(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } int count = 60; while (count > 0) { count--; Console.Title = string.Format("waiting {0}...", count); Task.Delay(1000).Wait(); } }