-
-
Save pelengami/d934280614653174df7c8b9b3240599c to your computer and use it in GitHub Desktop.
Get available udp port
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public bool TryGetAvailablePort(out int availableUdpPort) | |
{ | |
var activeUdpListeners = IPGlobalProperties.GetIPGlobalProperties().GetActiveUdpListeners(); | |
var range = Enumerable.Range(5000, 6000); | |
availableUdpPort = range.First(p => activeUdpListeners.All(l => l.Port != p)); | |
return availableUdpPort != -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment