NoSugarNet/Sample/NoSugarNet.ClientCli/Program.cs

61 lines
2.8 KiB
C#
Raw Normal View History

2024-01-22 11:58:24 +08:00
using NoSugarNet.ClientCore;
namespace NoSugarNet.ClientCli
{
internal class Program
{
static string Title = "NoSugarNetClient";
2024-01-22 11:58:24 +08:00
static void Main(string[] args)
{
2024-01-23 17:06:47 +08:00
if (!Config.LoadConfig())
{
Console.WriteLine("配置文件错误");
Console.ReadLine();
return;
}
AppNoSugarNet.OnUpdateStatus += OnUpdateStatus;
2024-04-15 15:16:10 +08:00
AppNoSugarNet.Init(OnNoSugarNetLog);
AppNoSugarNet.Connect(Config.ServerIP, Config.ServerPort);
2024-01-22 15:08:43 +08:00
while (true)
{
2024-04-15 15:16:10 +08:00
string CommandStr = Console.ReadLine();
string Command = "";
Command = ((CommandStr.IndexOf(" ") <= 0) ? CommandStr : CommandStr.Substring(0, CommandStr.IndexOf(" ")));
string[] CmdArr = CommandStr.Split(' ');
switch (Command)
{
case "con":
AppNoSugarNet.Connect(Config.ServerIP, Config.ServerPort);
break;
2024-06-21 17:17:32 +08:00
case "tlist":
AppNoSugarNet.local.GetClientCount(out int ClientUserCount, out int TunnelCount);
Console.WriteLine($"GetClientCount->{ClientUserCount} TunnelCount->{TunnelCount}");
AppNoSugarNet.local.GetClientDebugInfo();
break;
2024-04-15 15:16:10 +08:00
case "stop":
AppNoSugarNet.Close();
break;
default:
break;
}
2024-01-22 15:08:43 +08:00
}
2024-01-22 11:58:24 +08:00
}
2024-04-08 16:20:37 +08:00
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";
Console.Title = Title + info;
Console.WriteLine(info);
}
static string ConvertBytesToKilobytes(long bytes)
{
return Math.Round((double)bytes / 1024, 2).ToString("F2");
}
2024-04-15 11:30:28 +08:00
static void OnNoSugarNetLog(int LogLevel, string msg)
{
Console.WriteLine(msg);
}
2024-01-22 11:58:24 +08:00
}
}