History

GSF.Communication: Added more resilient ServerUri reporting for UdpClient.

J. Ritchie Carroll committed 5 years ago

Commit cb2a4541 parent 15cf7c72 files · +23 −2Browse files

Unified · Split

2 files
  1. Source/Libraries/GSF.Communication/Transport.cs +1 −1
  2. Source/Libraries/GSF.Communication/UdpClient.cs +22 −1
Source/Libraries/GSF.Communication/Transport.cs+1−1
@@ -131,7 +131,7 @@ namespace GSF.Communication · 130 unmodified lines
131131 #if !MONO
132132 if (stack == IPStack.IPv4 && !Socket.OSSupportsIPv4)
133133 throw new NotSupportedException($"IPv4 stack is not available for socket creation on {hostNameOrAddress.ToNonNullNorWhiteSpace("localhost")}:{port}");
134−#endif
134+ #endif
135135
136136 // No host name or IP address was specified, use local IPs
137137 if (string.IsNullOrWhiteSpace(hostNameOrAddress))
Source/Libraries/GSF.Communication/UdpClient.cs+22−1
@@ -325,7 +325,28 @@ namespace GSF.Communication · 324 unmodified lines
325325 /// Gets the server URI of the <see cref="UdpClient"/>.
326326 /// </summary>
327327 [Browsable(false)]
328− public override string ServerUri => $"{TransportProtocol}://{m_connectData["server"]}".ToLower();
328+ public override string ServerUri
329+ {
330+ get
331+ {
332+ if (m_connectData is null)
333+ return $"{TransportProtocol}://0.0.0.0:0";
334+
335+ if (m_connectData.ContainsKey("server"))
336+ return $"{TransportProtocol}://{m_connectData["server"]}".ToLower();
337+
338+ if (!m_connectData.TryGetValue("interface", out string targetInterface) || string.IsNullOrWhiteSpace(targetInterface))
339+ {
340+ IPStack ipStack = m_ipStack == IPStack.Default ? Transport.GetDefaultIPStack() : m_ipStack;
341+ targetInterface = ipStack == IPStack.IPv6 ? "[::0]" : "0.0.0.0";
342+ }
343+
344+ if (!m_connectData.TryGetValue("port", out string targetPort) || !ushort.TryParse(targetPort, out ushort port))
345+ port = 0;
346+
347+ return $"{TransportProtocol}://{targetInterface}:{port}".ToLower();
348+ }
349+ }
329350
330351 /// <summary>
331352 /// Gets or sets the size of the buffer used by the client for receiving data from the server.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t