Skip to content

Commit 1bd2df9

Browse files
committed
[修改]1. 修改网络帮助类的命名和本地地址的获取
1 parent be3137f commit 1bd2df9

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

GameFrameX.StartUp/AppStartUpByServer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ private async Task StartServer<TMessageDecoderHandler, TMessageEncoderHandler>(L
194194
{
195195
var hostBuilder = MultipleServerHostBuilder.Create();
196196
// 检查TCP端口是否可用
197-
if (Setting.InnerPort > 0 && Net.PortIsAvailable(Setting.InnerPort))
197+
if (Setting.InnerPort > 0 && NetHelper.PortIsAvailable(Setting.InnerPort))
198198
{
199199
LogHelper.InfoConsole($"启动 [TCP] 服务器 - 类型: {ServerType}, 地址: {Setting.InnerIp}, 端口: {Setting.InnerPort}");
200200
hostBuilder.ConfigureServices((context, collection) => { collection.Configure<ServerOptions>(ConfigureSuperSocket); });
@@ -215,7 +215,7 @@ private async Task StartServer<TMessageDecoderHandler, TMessageEncoderHandler>(L
215215
}
216216

217217
// 检查WebSocket端口是否可用
218-
if (Setting.WsPort is > 0 and < ushort.MaxValue && Net.PortIsAvailable(Setting.WsPort))
218+
if (Setting.WsPort is > 0 and < ushort.MaxValue && NetHelper.PortIsAvailable(Setting.WsPort))
219219
{
220220
LogHelper.InfoConsole("启动 [WebSocket] 服务器...");
221221

GameFrameX.StartUp/GameApp.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ private static void ApplicationPerformanceMonitorStart(string serverType)
207207
{
208208
if (appStartUp.ServerType == serverTypeValue && appStartUp.Setting.APMPort is > 0 and < ushort.MaxValue)
209209
{
210-
if (!Net.PortIsAvailable(appStartUp.Setting.APMPort))
210+
if (!NetHelper.PortIsAvailable(appStartUp.Setting.APMPort))
211211
{
212212
LogHelper.ErrorConsole("APM端口已被占用!=>" + appStartUp.Setting.APMPort);
213213
return;
Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
namespace GameFrameX.Utility;
66

77
/// <summary>
8-
/// 网络端口帮助类
8+
/// 网络帮助类
99
/// </summary>
10-
public static class Net
10+
public static class NetHelper
1111
{
1212
/// <summary>
1313
/// 判断IP地址是否合法
@@ -116,14 +116,21 @@ public static List<string> GetLocalIpList(AddressFamily addressFamily = AddressF
116116
foreach (var network in networkInterfaces)
117117
{
118118
// 排除非活动状态和环回接口
119-
if (network.OperationalStatus != OperationalStatus.Up ||
120-
network.NetworkInterfaceType == NetworkInterfaceType.Loopback)
119+
if (network.OperationalStatus != OperationalStatus.Up || network.NetworkInterfaceType == NetworkInterfaceType.Loopback)
121120
{
122121
continue;
123122
}
124123

124+
125125
// 获取网络接口的IP属性
126126
var properties = network.GetIPProperties();
127+
// 跳过没有网关的地址
128+
var gateways = properties.GatewayAddresses;
129+
if (gateways == null || gateways.Count == 0)
130+
{
131+
continue;
132+
}
133+
127134
foreach (var address in properties.UnicastAddresses)
128135
{
129136
// 根据指定的地址类型筛选IP

0 commit comments

Comments
 (0)