public string TcpPing(string endPoint) { if (endPoint.Split(':').Count() != 2) { throw new Exception("Please use dns:port format"); } var dns = endPoint.Split(':')[0]; var port = Convert.ToInt32(endPoint.Split(':')[1]); var times = new List <double>(); for (int i = 0; i < 4; i++) { var sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); sock.Blocking = true; var stopwatch = new Stopwatch(); // Measure the Connect call only stopwatch.Start(); var dnsEndPoint = new System.Net.DnsEndPoint(dns, port); sock.Connect(dnsEndPoint); stopwatch.Stop(); double t = stopwatch.Elapsed.TotalMilliseconds; Console.WriteLine("{0:0.00}ms", t); times.Add(t); sock.Close(); Thread.Sleep(1000); } return(string.Format("{0:0.00} {1:0.00} {2:0.00}", times.Min(), times.Max(), times.Average())); }
public SmtpHandler(System.Net.DnsEndPoint mailServer, string fromAddress, System.Collections.Generic.List <string> toAddress, string subject, int timeout = 1000) { this._mailServer = mailServer; this._fromAddress = fromAddress; this._toAddress = toAddress; this._subject = subject; this._timeout = timeout; }
// [Fact] public void TestSrvResolverWithSingleRecord() { var dnsEndPoint = new System.Net.DnsEndPoint("xmpp.ag-software.net", 5222); var ep = new DefaultNameResolver().ResolveAsync(dnsEndPoint).GetAwaiter().GetResult(); var resolver = new SrvNameResolver(); var ep2 = resolver.ResolveAsync(new System.Net.DnsEndPoint("ag-software.net", 80)).GetAwaiter().GetResult(); // assert resolver.DirectTls.ShouldBe(false); ep2.ToString().ShouldBe(ep.ToString()); }
public static bool TryParse(string s, int defaultPort, out System.Net.DnsEndPoint ep) { try { ep = Parse(s, defaultPort); return(true); } catch { ep = null; return(false); } }
public Arguments() { Servers = new System.Net.DnsEndPoint[0]; }