commit c5175e52e93884aaccf1878ef77a5f77844116c5
Author: SpringHgui <740360381@qq.com>
Date: Mon Dec 16 10:29:06 2019 +0800
init project
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..2cd48b4
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+bin
+obj
+.vs
diff --git a/FastTunnel.Client/Appsettings.cs b/FastTunnel.Client/Appsettings.cs
new file mode 100644
index 0000000..63c3286
--- /dev/null
+++ b/FastTunnel.Client/Appsettings.cs
@@ -0,0 +1,14 @@
+using FastTunnel.Core.Client;
+using FastTunnel.Core.Config;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace FastTunnel.Client
+{
+ public class Appsettings
+ {
+ public ClientConfig ClientSettings { get; set; }
+ }
+}
diff --git a/FastTunnel.Client/FastTunnel.Client.csproj b/FastTunnel.Client/FastTunnel.Client.csproj
new file mode 100644
index 0000000..5785046
--- /dev/null
+++ b/FastTunnel.Client/FastTunnel.Client.csproj
@@ -0,0 +1,27 @@
+
+
+
+ Exe
+ netcoreapp3.1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Always
+
+
+
+
diff --git a/FastTunnel.Client/Program.cs b/FastTunnel.Client/Program.cs
new file mode 100644
index 0000000..f2ac9a9
--- /dev/null
+++ b/FastTunnel.Client/Program.cs
@@ -0,0 +1,40 @@
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
+using FastTunnel.Core;
+using FastTunnel.Core.Client;
+using FastTunnel.Core.Logger;
+using System;
+using System.IO;
+using System.Net;
+using System.Net.Sockets;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace FastTunnel.Client
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ Console.WriteLine("Client Start!");
+
+ var conf = new ConfigurationBuilder()
+ .SetBasePath(Directory.GetCurrentDirectory())
+ .AddJsonFile("appsettings.json", true, true)
+ .Build();
+
+ var settings = conf.Get();
+
+ Run(settings);
+ }
+
+ private static void Run(Appsettings settings)
+ {
+ var FastTunnelClient = new FastTunnelClient(settings.ClientSettings, new ConsoleLogger());
+ FastTunnelClient.Login();
+
+ Console.ReadLine();
+ }
+ }
+}
diff --git a/FastTunnel.Client/SuiDao.Client.csproj.user b/FastTunnel.Client/SuiDao.Client.csproj.user
new file mode 100644
index 0000000..966b4ff
--- /dev/null
+++ b/FastTunnel.Client/SuiDao.Client.csproj.user
@@ -0,0 +1,6 @@
+
+
+
+ true
+
+
\ No newline at end of file
diff --git a/FastTunnel.Client/appsettings.json b/FastTunnel.Client/appsettings.json
new file mode 100644
index 0000000..309bf91
--- /dev/null
+++ b/FastTunnel.Client/appsettings.json
@@ -0,0 +1,31 @@
+{
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft": "Warning",
+ "Microsoft.Hosting.Lifetime": "Information"
+ }
+ },
+ "ClientSettings": {
+ "Common": {
+ // 服务端公网ip
+ "ServerAddr": "127.0.0.1",
+
+ // 服务端通信端口
+ "ServerPort": 1271
+ },
+ "Webs": [
+ {
+ // 本地站点所在内网的ip
+ "LocalIp": "127.0.0.1",
+
+ // 站点监听的端口号
+ "LocalPort": 9000,
+
+ // 子域名
+ "SubDomain": "test"
+ }
+ ]
+
+ }
+}
\ No newline at end of file
diff --git a/FastTunnel.Core/Client/SuiDaoClient.cs b/FastTunnel.Core/Client/SuiDaoClient.cs
new file mode 100644
index 0000000..a1aaba3
--- /dev/null
+++ b/FastTunnel.Core/Client/SuiDaoClient.cs
@@ -0,0 +1,126 @@
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+using FastTunnel.Core.Config;
+using FastTunnel.Core.Logger;
+using FastTunnel.Core.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net.Sockets;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace FastTunnel.Core.Client
+{
+ public class FastTunnelClient
+ {
+ ClientConfig _clientConfig;
+
+ Connecter connecter;
+
+ ILogger _logger;
+
+ public FastTunnelClient(ClientConfig clientConfig, ILogger logger)
+ {
+ _logger = logger;
+ _clientConfig = clientConfig;
+ connecter = new Connecter(_clientConfig.Common.ServerAddr, _clientConfig.Common.ServerPort);
+ }
+
+ public void Login()
+ {
+ //连接到的目标IP
+ connecter.Connect();
+
+ // 登录
+ connecter.Send(new Message { MessageType = MessageType.C_LogIn, Content = new LogInRequest { WebList = _clientConfig.Webs } });
+
+ _logger.Info("登录成功");
+ Thread th = new Thread(ReceiveServer);
+ th.IsBackground = true;
+ th.Start(connecter.Client);
+ }
+
+ private void ReceiveServer(object obj)
+ {
+ var client = obj as Socket;
+ byte[] buffer = new byte[1024];
+
+ string lastBuffer = string.Empty;
+ while (true)
+ {
+ int n = client.Receive(buffer);
+ string words = Encoding.UTF8.GetString(buffer, 0, n);
+ if (!string.IsNullOrEmpty(lastBuffer))
+ {
+ words = lastBuffer + words;
+ lastBuffer = null;
+ }
+
+ _logger.Info($"收到服务端 {words}");
+ var msgs = words.Split("\n");
+
+ try
+ {
+ foreach (var item in msgs)
+ {
+ if (!string.IsNullOrEmpty(item))
+ {
+ if (item.EndsWith("}"))
+ {
+ HandleServerRequest(item);
+ }
+ else
+ {
+ lastBuffer = item;
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.Error(ex.Message);
+ continue;
+ }
+ }
+ }
+
+ private void HandleServerRequest(string words)
+ {
+ Message