Skip to content

Commit

Permalink
fix: 修复端口被占用后本地TCP服务器无法再打开的问题 #171
Browse files Browse the repository at this point in the history
  • Loading branch information
itldg authored and chenxuuu committed Jul 4, 2024
1 parent 79f610f commit 9ec59db
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions llcom/Pages/TcpLocalPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,17 @@ private bool StartServer(string ip, int port)
if (Server != null)
return false;
IPAddress localAddr = IPAddress.Parse(ip);
Server = new TcpListener(localAddr, port);
Server.Start();
try
{
Server = new TcpListener(localAddr, port);
Server.Start();
}
catch (Exception ex)
{
Server = null;
throw ex;
}

var isV6 = ip.Contains(":");
ShowData($"🛰 {(isV6 ? "[" : "")}{ip}{(isV6 ? "]" : "")}:{port}");
AsyncCallback newConnectionCb = null;
Expand Down

0 comments on commit 9ec59db

Please sign in to comment.