Skip to content

Commit

Permalink
Fix port use
Browse files Browse the repository at this point in the history
  • Loading branch information
contactsamie committed Jun 29, 2021
1 parent f058c2f commit 14a8e0b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions ServeMeLib/ServeMe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ internal string CanOpenDefaultBrowserOnStart(string root)
}

//https://stackoverflow.com/questions/570098/in-c-how-to-check-if-a-tcp-port-is-available
internal bool PortInUse(int port)
internal bool PortNotInUse(int port)
{
bool isAvailable = true;
IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
Expand Down Expand Up @@ -433,7 +433,7 @@ internal List<List<string>> GetVariablesFromSettings()
if (this.ExtractFromSettings("app sslport", out data) == 2)
{
int port = int.Parse(data[1]);
if (this.PortInUse(port))
if (!this.PortNotInUse(port))
throw new Exception($"Ssl Port {port} in setting is in use");
return port;
}
Expand All @@ -446,7 +446,7 @@ internal List<List<string>> GetVariablesFromSettings()
if (this.ExtractFromSettings("app port", out data) == 2)
{
int port = int.Parse(data[1]);
if (this.PortInUse(port))
if (!this.PortNotInUse(port))
throw new Exception($"Port {port} in setting is in use");
return port;
}
Expand Down
4 changes: 2 additions & 2 deletions ServeMeLib/SimpleHttpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ public SimpleHttpServer(ServeMe serveMe, int? port = null, int? portHttps = null
}
if (portHttps == null)
{
var allowableHttpsPortsByVisualStudio = Enumerable.Range(44300, 33399).ToList();
var allowableHttpsPortsByVisualStudio = Enumerable.Range(44300, 44399).ToList();

for (int i = 0; i < allowableHttpsPortsByVisualStudio.Count; i++)
{
if (!serveMe.PortInUse(allowableHttpsPortsByVisualStudio[i]))
if (serveMe.PortNotInUse(allowableHttpsPortsByVisualStudio[i]))
{
portHttps = allowableHttpsPortsByVisualStudio[i];
serveMe.Log($"Yay! Found https port {portHttps} to use ....");
Expand Down

0 comments on commit 14a8e0b

Please sign in to comment.