private async Task RespondToV2Message(string messageText, IpEndPointInfo endpoint, Encoding encoding) { var parts = messageText.Split('|'); var localUrl = await _appHost.GetLocalApiUrl().ConfigureAwait(false); if (!string.IsNullOrEmpty(localUrl)) { var response = new ServerDiscoveryInfo { Address = localUrl, Id = _appHost.SystemId, Name = _appHost.FriendlyName }; await SendAsync(encoding.GetBytes(_json.SerializeToString(response)), endpoint).ConfigureAwait(false); if (parts.Length > 1) { _appHost.EnableLoopback(parts[1]); } } else { _logger.Warn("Unable to respond to udp request because the local ip address could not be determined."); } }
private async Task RespondToV2Message(EndPoint endpoint, CancellationToken cancellationToken) { string?localUrl = _config[AddressOverrideConfigKey]; if (string.IsNullOrEmpty(localUrl)) { localUrl = _appHost.GetSmartApiUrl(((IPEndPoint)endpoint).Address); } if (string.IsNullOrEmpty(localUrl)) { _logger.LogWarning("Unable to respond to udp request because the local ip address could not be determined."); return; } var response = new ServerDiscoveryInfo(localUrl, _appHost.SystemId, _appHost.FriendlyName); try { await _udpSocket.SendToAsync(JsonSerializer.SerializeToUtf8Bytes(response), SocketFlags.None, endpoint, cancellationToken).ConfigureAwait(false); } catch (SocketException ex) { _logger.LogError(ex, "Error sending response message"); } }
private async Task RespondToV2Message(string messageText, EndPoint endpoint, CancellationToken cancellationToken) { var localUrl = await _appHost.GetLocalApiUrl(cancellationToken).ConfigureAwait(false); if (!string.IsNullOrEmpty(localUrl)) { var response = new ServerDiscoveryInfo { Address = localUrl, Id = _appHost.SystemId, Name = _appHost.FriendlyName }; try { await _udpSocket.SendToAsync(JsonSerializer.SerializeToUtf8Bytes(response), SocketFlags.None, endpoint).ConfigureAwait(false); } catch (SocketException ex) { _logger.LogError(ex, "Error sending response message"); } var parts = messageText.Split('|'); if (parts.Length > 1) { _appHost.EnableLoopback(parts[1]); } } else { _logger.LogWarning("Unable to respond to udp request because the local ip address could not be determined."); } }
private Uri ConvertEndpointAddressToManualAddress(ServerDiscoveryInfo info) { if (!string.IsNullOrWhiteSpace(info.Address) && !string.IsNullOrWhiteSpace(info.EndpointAddress)) { var uriBuilder = new UriBuilder(info.EndpointAddress.Split(':').First()) { Port = new Uri(info.Address).Port }; return(uriBuilder.Uri); } return(null); }
public void Browse() { if (servers.Count > 0) { return; } var fooServer = new ServerDiscoveryInfo(Dns.GetHostEntry(IPAddress.Loopback), "Foo", "Test"); servers.Add(fooServer); ServiceFound?.Invoke(this, fooServer); var barServer = new ServerDiscoveryInfo(Dns.GetHostEntry(Dns.GetHostName()), "Bar", "Test"); servers.Add(barServer); ServiceFound?.Invoke(this, barServer); }
private async void RespondToV2Message(string endpoint, Encoding encoding) { var localUrl = _appHost.LocalApiUrl; if (!string.IsNullOrEmpty(localUrl)) { var response = new ServerDiscoveryInfo { Address = localUrl, Id = _appHost.SystemId, Name = _appHost.FriendlyName }; await SendAsync(encoding.GetBytes(_json.SerializeToString(response)), endpoint); } else { _logger.Warn("Unable to respond to udp request because the local ip address could not be determined."); } }
private async void RespondToV2Message(string endpoint) { var info = _appHost.GetSystemInfo(); if (!string.IsNullOrEmpty(info.LocalAddress)) { var response = new ServerDiscoveryInfo { Address = info.LocalAddress, Id = info.Id, Name = info.ServerName }; await SendAsync(Encoding.UTF8.GetBytes(_json.SerializeToString(response)), endpoint); } else { _logger.Warn("Unable to respond to udp request because the local ip address could not be determined."); } }
private async void RespondToV2Message(string endpoint) { var localAddress = GetLocalIpAddress(); if (!string.IsNullOrEmpty(localAddress)) { var serverAddress = string.Format("http://{0}:{1}", localAddress, _serverConfigurationManager.Configuration.HttpServerPortNumber); var response = new ServerDiscoveryInfo { Address = serverAddress, Id = _appHost.ServerId, Name = _appHost.FriendlyName }; await SendAsync(Encoding.UTF8.GetBytes(_json.SerializeToString(response)), endpoint); } else { _logger.Warn("Unable to respond to udp request because the local ip address could not be determined."); } }
private string ConvertEndpointAddressToManualAddress(ServerDiscoveryInfo info) { if (!string.IsNullOrWhiteSpace(info.Address) && !string.IsNullOrWhiteSpace(info.EndpointAddress)) { var address = info.EndpointAddress.Split(':').First(); // Determine the port, if any var parts = info.Address.Split(':'); if (parts.Length > 1) { var portString = parts.Last(); int port; if (int.TryParse(portString, NumberStyles.Any, CultureInfo.InvariantCulture, out port)) { address += ":" + portString; } } return(NormalizeAddress(address)); } return(null); }