NoSugarNet/Sample/NoSugarNet.ServerCli/Program.cs

53 lines
2.4 KiB
C#
Raw Normal View History

using NoSugarNet.ServerCore;
using NoSugarNet.ServerCore.Common;
using ServerCore.Manager;
2024-01-22 11:58:24 +08:00
namespace NoSugarNet.ServerCli
{
internal class Program
{
static string Title = "NoSugarNetServer";
2024-01-22 11:58:24 +08:00
static void Main(string[] args)
{
2024-01-23 17:06:47 +08:00
Console.ForegroundColor = ConsoleColor.Green;
2024-01-22 15:08:43 +08:00
if (!Config.LoadConfig())
{
Console.WriteLine("配置文件错误");
Console.ReadLine();
return;
}
Dictionary<byte, TunnelClientData> dictTunnel = new Dictionary<byte, TunnelClientData>();
for (int i = 0; i < Config.cfg.TunnelList.Count; i++)
{
ConfigDataModel_Single cfgSingle = Config.cfg.TunnelList[i];
dictTunnel[(byte)i] = new TunnelClientData()
{
TunnelId = (byte)i,
ServerLocalTargetIP = cfgSingle.ServerLocalTargetIP,
ServerLocalTargetPort = (ushort)cfgSingle.ServerLocalTargetPort,
ClientLocalPort = (ushort)cfgSingle.ClientLocalPort,
};
}
ServerManager.OnUpdateStatus += OnUpdateStatus;
2024-01-25 17:17:16 +08:00
ServerManager.InitServer(Config.cfg.ServerPort, dictTunnel,Config.cfg.CompressAdapterType);
2024-01-22 15:08:43 +08:00
2024-01-22 11:58:24 +08:00
while (true)
{
Console.ReadLine();
}
}
static void OnUpdateStatus(NetStatus netState)
{
2024-04-08 16:20:37 +08:00
//string info = $"User:{netState.ClientUserCount} Tun:{netState.TunnelCount} rec:{netState.srcReciveAllLenght}|{netState.tReciveAllLenght} {ConvertBytesToKilobytes(netState.srcReciveSecSpeed)}K/s|{ConvertBytesToKilobytes(netState.tReciveSecSpeed)}K/s send:{netState.srcSendAllLenght}|{netState.tSendAllLenght} {ConvertBytesToKilobytes(netState.srcSendSecSpeed)}K/s|{ConvertBytesToKilobytes(netState.tSendSecSpeed)}K/s";
string info = $"User:{netState.ClientUserCount} Tun:{netState.TunnelCount} rec: {ConvertBytesToKilobytes(netState.srcReciveSecSpeed)}K/s|{ConvertBytesToKilobytes(netState.tReciveSecSpeed)}K/s send: {ConvertBytesToKilobytes(netState.srcSendSecSpeed)}K/s|{ConvertBytesToKilobytes(netState.tSendSecSpeed)}K/s";
2024-01-25 17:17:16 +08:00
Console.Title = Title + info;
Console.WriteLine(info);
}
2024-04-08 16:20:37 +08:00
static string ConvertBytesToKilobytes(long bytes)
{
2024-04-08 16:20:37 +08:00
return Math.Round((double)bytes / 1024, 2).ToString("F2");
}
2024-01-22 11:58:24 +08:00
}
}