Answers for "how to check if the server is listening on port in c#"

C#
0

how to check if the server is listening on port in c#

public static bool PortInUse(int  port)
 {
     bool inUse = false;
             
     IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();
     IPEndPoint [] ipEndPoints = ipProperties.GetActiveTcpListeners();

 
     foreach(IPEndPoint endPoint in ipEndPoints)
     {
         if  (endPoint.Port == port)
         {
             inUse = true;
             break;
         }
     }

 
     return  inUse;
 }
// this function returns true only for local endpoints!!
Posted by: Guest on December-16-2020

Code answers related to "how to check if the server is listening on port in c#"

C# Answers by Framework

Browse Popular Code Answers by Language