Created
July 19, 2017 18:43
-
-
Save yallie/df43f8426aef0c1d6527afb7f4262c2f to your computer and use it in GitHub Desktop.
IsServerRunning — checks whether a server is running at the specified endpoint
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 static bool IsServerRunning(string url) | |
{ | |
if (string.IsNullOrWhiteSpace(url)) | |
{ | |
throw new ArgumentNullException("url"); | |
} | |
Uri uri; | |
try | |
{ | |
uri = new Uri(url); | |
} | |
catch (Exception ex) | |
{ | |
throw new ArgumentException("url", ex); | |
} | |
try | |
{ | |
using (var tcp = new TcpClient()) | |
{ | |
tcp.Connect(uri.Host, uri.Port); | |
return true; | |
} | |
} | |
catch | |
{ | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A few notes: