public void DefaultServer() { var server = new StunServer(); Assert.AreEqual(@"stun.syncthing.net", server.Hostname); Assert.AreEqual(3478, server.Port); }
private async Task DiscoveryNatTypeImpl(CancellationToken token) { var server = new StunServer(); if (!server.Parse(_config.StunServer)) { throw new Exception(@"Wrong STUN Server!"); } using var proxy = ProxyFactory.CreateProxy( _config.ProxyType, Result5389.LocalEndPoint, NetUtils.ParseEndpoint(_config.ProxyServer), _config.ProxyUser, _config.ProxyPassword ); using var client = new StunClient5389UDP(server.Hostname, server.Port, Result5389.LocalEndPoint, proxy); Result5389 = client.Status; await client.QueryAsync(); var cache = new StunResult5389(); cache.Clone(client.Status); cache.LocalEndPoint = client.LocalEndPoint; Result5389 = cache; }
public void TestDefaultPort(string str) { Assert.IsTrue(StunServer.TryParse(str, out var server)); Assert.IsNotNull(server); Assert.AreEqual(str, server.Hostname); Assert.AreEqual(3478, server.Port); }
private async void TestButton_OnClick(object sender, RoutedEventArgs e) { var stun = new StunServer(); if (stun.Parse(ServersComboBox.Text)) { var server = stun.Hostname; var port = stun.Port; var local = LocalEndTextBox.Text; TestButton.IsEnabled = false; await Task.Run(() => { var(natType, localEnd, publicEnd) = NetUtils.NatTypeTestCore(local, server, port); Dispatcher?.InvokeAsync(() => { NatTypeTextBox.Text = natType; LocalEndTextBox.Text = localEnd; PublicEndTextBox.Text = publicEnd; TestButton.IsEnabled = true; }); }); } else { MessageBox.Show(@"Wrong Stun server!", @"NatTypeTester", MessageBoxButton.OK, MessageBoxImage.Error); } }
static void Main(string[] args) { int listenPort = 3478; // wenn Port angegeben Standard Port überschreiben if (args.Length == 1) listenPort = int.Parse(args[0]); // localEndPoint IP Adresse eventuell anpassen an gleichen localEndPoint wie andere Socket wegen S-O IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, listenPort); TcpListener listener = new TcpListener(localEndPoint); listener.Start(); Console.WriteLine("Server started on Port {0}.", listenPort); while (true) { TcpClient stunClient = listener.AcceptTcpClient(); StunServer stunServer = new StunServer(stunClient); } }
public void IsTrue(string host, ushort port) { var str = $@"{host}:{port}"; Assert.IsTrue(StunServer.TryParse(str, out var server)); Assert.IsNotNull(server); Assert.AreEqual(host, server.Hostname); Assert.AreEqual(port, server.Port); Assert.AreEqual(str, server.ToString()); }
private async void LoadStunServer() { const string path = @"stun.txt"; if (File.Exists(path)) { using var sw = new StreamReader(path); string line; var stun = new StunServer(); while ((line = await sw.ReadLineAsync()) != null) { if (!string.IsNullOrWhiteSpace(line) && stun.Parse(line)) { StunServers.Add(stun.ToString()); } } } }
private async Task TestClassicNatTypeImpl(CancellationToken token) { var server = new StunServer(); if (!server.Parse(_config.StunServer)) { throw new Exception(@"Wrong STUN Server!"); } using var proxy = ProxyFactory.CreateProxy( _config.ProxyType, Result3489.LocalEndPoint, NetUtils.ParseEndpoint(_config.ProxyServer), _config.ProxyUser, _config.ProxyPassword ); using var client = new StunClient3489(server.Hostname, server.Port, Result3489.LocalEndPoint, proxy); Result3489 = client.Status; await client.Query3489Async(); Result3489.LocalEndPoint = client.LocalEndPoint; }
public void ToString(string str, string expected) { Assert.IsTrue(StunServer.TryParse(str, out var server)); Assert.IsNotNull(server); Assert.AreEqual(expected, server.ToString()); }
public void IsFalse(string str) { Assert.IsFalse(StunServer.TryParse(str, out var server)); Assert.IsNull(server); }