初版可用
This commit is contained in:
parent
a07a964a0f
commit
246bb83495
@ -220,7 +220,7 @@ namespace ServerCore.Manager
|
|||||||
/// <param name="data"></param>
|
/// <param name="data"></param>
|
||||||
public void OnServerLocalDataCallBack(byte tunnelId,byte Idx, byte[] data)
|
public void OnServerLocalDataCallBack(byte tunnelId,byte Idx, byte[] data)
|
||||||
{
|
{
|
||||||
AppNoSugarNet.log.Debug($"OnServerLocalDataCallBack {tunnelId},{Idx}");
|
AppNoSugarNet.log.Debug($"OnServerLocalDataCallBack {tunnelId},{Idx},Data长度:{data.Length}");
|
||||||
if (!GetLocalListener(tunnelId, out LocalListener _listener))
|
if (!GetLocalListener(tunnelId, out LocalListener _listener))
|
||||||
return;
|
return;
|
||||||
//解压
|
//解压
|
||||||
|
@ -58,7 +58,7 @@ namespace NoSugarNet.ClientCore
|
|||||||
|
|
||||||
public void DataCallBack(Socket sk, byte[] data)
|
public void DataCallBack(Socket sk, byte[] data)
|
||||||
{
|
{
|
||||||
AppNoSugarNet.log.Debug("收到消息 数据长度=>" + data.Length);
|
//AppNoSugarNet.log.Debug("收到消息 数据长度=>" + data.Length);
|
||||||
|
|
||||||
if (!GetSocketIdxBySocket(sk, out int Idx))
|
if (!GetSocketIdxBySocket(sk, out int Idx))
|
||||||
return;
|
return;
|
||||||
@ -201,9 +201,9 @@ namespace NoSugarNet.ClientCore
|
|||||||
if (!GetSocketByIdx(Idx, out LocalClientInfo _localClientInfo))
|
if (!GetSocketByIdx(Idx, out LocalClientInfo _localClientInfo))
|
||||||
return;
|
return;
|
||||||
if (bConnected)
|
if (bConnected)
|
||||||
AppNoSugarNet.log.Debug("远端本地连接已连接");
|
AppNoSugarNet.log.Debug("远端本地连接已连接!!!!");
|
||||||
else
|
else
|
||||||
AppNoSugarNet.log.Debug("远端本地连接已断开连接");
|
AppNoSugarNet.log.Debug("远端本地连接已断开连接!!!!");
|
||||||
_localClientInfo.bRemoteConnect = bConnected;
|
_localClientInfo.bRemoteConnect = bConnected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net7.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
6
NoSugarNet.ClientCore/NoSugarNet.ClientCore.csproj.user
Normal file
6
NoSugarNet.ClientCore/NoSugarNet.ClientCore.csproj.user
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<_LastSelectedProfileId>F:\Sin365\NoSugarNet\NoSugarNet.ClientCore\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
https://go.microsoft.com/fwlink/?LinkID=208121.
|
||||||
|
-->
|
||||||
|
<Project>
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Any CPU</Platform>
|
||||||
|
<PublishDir>bin\Release\net8.0\publish\</PublishDir>
|
||||||
|
<PublishProtocol>FileSystem</PublishProtocol>
|
||||||
|
<_TargetId>Folder</_TargetId>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<SelfContained>false</SelfContained>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
https://go.microsoft.com/fwlink/?LinkID=208121.
|
||||||
|
-->
|
||||||
|
<Project>
|
||||||
|
<PropertyGroup>
|
||||||
|
<History>True|2024-01-23T08:25:49.0876201Z;</History>
|
||||||
|
<LastFailureDetails />
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
@ -108,7 +108,7 @@ namespace ServerCore.Manager
|
|||||||
/// <param name="tunnelId"></param>
|
/// <param name="tunnelId"></param>
|
||||||
void OnClientLocalConnect(long uid, byte tunnelId,int Idx)
|
void OnClientLocalConnect(long uid, byte tunnelId,int Idx)
|
||||||
{
|
{
|
||||||
ServerManager.g_Log.Debug($"OnClientLocalConnect {uid},{tunnelId},{Idx}");
|
ServerManager.g_Log.Debug($"OnClientLocalConnect!!!!!! {uid},{tunnelId},{Idx}");
|
||||||
if (!ServerManager.g_ClientMgr.GetClientByUID(uid, out ClientInfo client))
|
if (!ServerManager.g_ClientMgr.GetClientByUID(uid, out ClientInfo client))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -145,7 +145,7 @@ namespace ServerCore.Manager
|
|||||||
/// <param name="tunnelId"></param>
|
/// <param name="tunnelId"></param>
|
||||||
void OnClientLocalDisconnect(long uid, byte tunnelId,byte Idx)
|
void OnClientLocalDisconnect(long uid, byte tunnelId,byte Idx)
|
||||||
{
|
{
|
||||||
ServerManager.g_Log.Debug($"OnClientLocalDisconnect {uid},{tunnelId},{Idx}");
|
ServerManager.g_Log.Debug($"OnClientLocalDisconnect,收到客户端断开链接!!!!!! {uid},{tunnelId},{Idx}");
|
||||||
if (!ServerManager.g_ClientMgr.GetClientByUID(uid, out ClientInfo client))
|
if (!ServerManager.g_ClientMgr.GetClientByUID(uid, out ClientInfo client))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ namespace ServerCore.Manager
|
|||||||
if (!GetServerLocalClient(uid, tunnelId, Idx, out ServerLocalClient serverLocalClient))
|
if (!GetServerLocalClient(uid, tunnelId, Idx, out ServerLocalClient serverLocalClient))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//清楚服务器数据
|
//清除服务器数据
|
||||||
RemoveServerLocalClient(uid, tunnelId, Idx);
|
RemoveServerLocalClient(uid, tunnelId, Idx);
|
||||||
//断开服务端本地客户端连接
|
//断开服务端本地客户端连接
|
||||||
serverLocalClient.CloseConntect();
|
serverLocalClient.CloseConntect();
|
||||||
|
@ -55,7 +55,7 @@ namespace NoSugarNet.ClientCore.Network
|
|||||||
/// <param name="data">业务数据</param>
|
/// <param name="data">业务数据</param>
|
||||||
public void GetDataCallBack(byte[] data)
|
public void GetDataCallBack(byte[] data)
|
||||||
{
|
{
|
||||||
NetworkDeBugLog("收到消息 数据长度=>" + data.Length);
|
//NetworkDeBugLog("收到消息 数据长度=>" + data.Length);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//抛出网络数据
|
//抛出网络数据
|
||||||
|
@ -23,7 +23,8 @@ namespace ServerCore.Manager
|
|||||||
g_Login = new LoginManager();
|
g_Login = new LoginManager();
|
||||||
g_Chat = new ChatManager();
|
g_Chat = new ChatManager();
|
||||||
g_Local = new LocalClientManager();
|
g_Local = new LocalClientManager();
|
||||||
g_SocketMgr = new IOCPNetWork(1024, 1024);
|
//g_SocketMgr = new IOCPNetWork(1024, 1024);
|
||||||
|
g_SocketMgr = new IOCPNetWork(1024, 4096);
|
||||||
g_SocketMgr.Init();
|
g_SocketMgr.Init();
|
||||||
g_SocketMgr.Start(new IPEndPoint(IPAddress.Any.Address, port));
|
g_SocketMgr.Start(new IPEndPoint(IPAddress.Any.Address, port));
|
||||||
Console.WriteLine("Succeed!");
|
Console.WriteLine("Succeed!");
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net7.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
51
README.md
51
README.md
@ -1,3 +1,54 @@
|
|||||||
# NoSugarNet
|
# NoSugarNet
|
||||||
|
|
||||||
NoSugarNet(无糖网络),一个有效降低任意C/S程序(软件,程序)网络流量传输的网络中间工具。
|
NoSugarNet(无糖网络),一个有效降低任意C/S程序(软件,程序)网络流量传输的网络中间工具。
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 流程诠释:
|
||||||
|
|
||||||
|
【需要代理的程序】<----Localhost本地通讯----->【NoSugarNet.Client】 <----代理通讯-----> 【NoSugarNet.ServerCli】<----服务端本地-----> 【目标服务端程序】
|
||||||
|
|
||||||
|
————————————————————
|
||||||
|
|
||||||
|
# 服务端 NoSugarNet.ServerCli
|
||||||
|
|
||||||
|
其中config.cfg 是配置文件
|
||||||
|
|
||||||
|
格式:
|
||||||
|
|
||||||
|
```
|
||||||
|
<配置编号>:<目标服务端IP>:<目标服务器端口>:<客户端监听的端口>
|
||||||
|
```
|
||||||
|
|
||||||
|
每个配置换行
|
||||||
|
|
||||||
|
形如
|
||||||
|
|
||||||
|
```
|
||||||
|
0:1.2.3.4:3389:10001
|
||||||
|
1:1.2.3.5:3389:10002
|
||||||
|
```
|
||||||
|
|
||||||
|
表示
|
||||||
|
|
||||||
|
本代理服务,可以连接代理访问,1.2.3.4:3389 和 1.2.3.5:3389
|
||||||
|
|
||||||
|
配置编号和客户端安排端口会发送到给客户端。
|
||||||
|
|
||||||
|
客户端连接服务器获取基本信息后,客户端会开始监听10001和10002
|
||||||
|
|
||||||
|
————————————————————
|
||||||
|
|
||||||
|
客户端 NoSugarNet.ClientCli
|
||||||
|
|
||||||
|
其中config.cfg 是配置文件
|
||||||
|
|
||||||
|
格式:
|
||||||
|
|
||||||
|
```
|
||||||
|
<代理服务端IP>:<代理服务端Port>
|
||||||
|
```
|
||||||
|
|
||||||
|
*代理端口IP可以改,端口哦固定为1000,因为服务器中转端口写死的1000(笑)
|
||||||
|
|
||||||
|
|
||||||
|
42
Sample/NoSugarNet.ClientCli/Config.cs
Normal file
42
Sample/NoSugarNet.ClientCli/Config.cs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace NoSugarNet.ClientCli
|
||||||
|
{
|
||||||
|
public static class Config
|
||||||
|
{
|
||||||
|
public static string ServerIP;
|
||||||
|
public static int ServerPort;
|
||||||
|
public static bool LoadConfig()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
StreamReader sr = new StreamReader(System.Environment.CurrentDirectory + "//config.cfg", Encoding.Default);
|
||||||
|
String line;
|
||||||
|
while (!string.IsNullOrEmpty((line = sr.ReadLine())))
|
||||||
|
{
|
||||||
|
if (!line.Contains(":"))
|
||||||
|
continue;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ServerIP = line.Split(':')[0].Trim();
|
||||||
|
ServerPort = Convert.ToInt32(line.Split(':')[1].Trim());
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sr.Close();
|
||||||
|
if (!string.IsNullOrEmpty(ServerIP))
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("配置文件异常:" + ex.ToString());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +1,20 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net7.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Remove="config.cfg" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Page Include="config.cfg" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\NoSugarNet.ClientCore\NoSugarNet.ClientCore.csproj" />
|
<ProjectReference Include="..\..\NoSugarNet.ClientCore\NoSugarNet.ClientCore.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<_LastSelectedProfileId>F:\Sin365\NoSugarNet\Sample\NoSugarNet.ClientCli\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
@ -6,7 +6,13 @@ namespace NoSugarNet.ClientCli
|
|||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
AppNoSugarNet.Init("127.0.0.1", 1000);
|
if (!Config.LoadConfig())
|
||||||
|
{
|
||||||
|
Console.WriteLine("配置文件错误");
|
||||||
|
Console.ReadLine();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AppNoSugarNet.Init(Config.ServerIP, Config.ServerPort);
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
Console.ReadLine();
|
Console.ReadLine();
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
https://go.microsoft.com/fwlink/?LinkID=208121.
|
||||||
|
-->
|
||||||
|
<Project>
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Any CPU</Platform>
|
||||||
|
<PublishDir>bin\Release\net8.0\publish\win-x64\</PublishDir>
|
||||||
|
<PublishProtocol>FileSystem</PublishProtocol>
|
||||||
|
<_TargetId>Folder</_TargetId>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||||
|
<SelfContained>false</SelfContained>
|
||||||
|
<PublishSingleFile>false</PublishSingleFile>
|
||||||
|
<PublishReadyToRun>false</PublishReadyToRun>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
https://go.microsoft.com/fwlink/?LinkID=208121.
|
||||||
|
-->
|
||||||
|
<Project>
|
||||||
|
<PropertyGroup>
|
||||||
|
<History>True|2024-01-23T08:35:06.3918472Z;True|2024-01-23T16:34:52.0595483+08:00;True|2024-01-23T16:27:36.4850749+08:00;True|2024-01-23T16:27:04.0721589+08:00;</History>
|
||||||
|
<LastFailureDetails />
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
1
Sample/NoSugarNet.ClientCli/config.cfg
Normal file
1
Sample/NoSugarNet.ClientCli/config.cfg
Normal file
@ -0,0 +1 @@
|
|||||||
|
127.0.0.1:1000
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net7.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<_LastSelectedProfileId>F:\Sin365\NoSugarNet\Sample\NoSugarNet.ServerCli\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
@ -6,6 +6,7 @@ namespace NoSugarNet.ServerCli
|
|||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
if (!Config.LoadConfig())
|
if (!Config.LoadConfig())
|
||||||
{
|
{
|
||||||
Console.WriteLine("配置文件错误");
|
Console.WriteLine("配置文件错误");
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
https://go.microsoft.com/fwlink/?LinkID=208121.
|
||||||
|
-->
|
||||||
|
<Project>
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Any CPU</Platform>
|
||||||
|
<PublishDir>bin\Release\net8.0\publish\win-x64\</PublishDir>
|
||||||
|
<PublishProtocol>FileSystem</PublishProtocol>
|
||||||
|
<_TargetId>Folder</_TargetId>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||||
|
<SelfContained>false</SelfContained>
|
||||||
|
<PublishSingleFile>false</PublishSingleFile>
|
||||||
|
<PublishReadyToRun>false</PublishReadyToRun>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
https://go.microsoft.com/fwlink/?LinkID=208121.
|
||||||
|
-->
|
||||||
|
<Project>
|
||||||
|
<PropertyGroup>
|
||||||
|
<History>True|2024-01-23T08:36:21.1141328Z;</History>
|
||||||
|
<LastFailureDetails />
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
@ -1,4 +1,2 @@
|
|||||||
0:127.0.0.1:3306:10001
|
0:1.2.3.4:3389:10001
|
||||||
1:127.0.0.1:3306:10002
|
1:1.2.3.5:3389:10002
|
||||||
2:127.0.0.1:3306:10003
|
|
||||||
3:127.0.0.1:3306:10004
|
|
Loading…
Reference in New Issue
Block a user