A:全局Common的公共定义

This commit is contained in:
jimmy committed 2025-05-26 22:56:51 +08:00
1 parent 83b7ca5971
commit eaaedd48cf
18 files changed
+366 -1

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
using System.Net;
using System.Net.Sockets;
namespace Application.Utils;
/// <summary>
///
/// </summary>
public static class SysHelper
{
/// <summary>
/// 获取可用端口
/// </summary>
/// <returns></returns>
public static int GetAvailablePort()
{
TcpListener listener = new TcpListener(IPAddress.Loopback, 0); // 端口号为0表示由系统自动分配
listener.Start();
int port = ((IPEndPoint)listener.LocalEndpoint).Port;
listener.Stop();
return port;
}
}