diff --git a/FastTunel.Core.WebApi/Properties/launchSettings.json b/FastTunel.Core.WebApi/Properties/launchSettings.json new file mode 100644 index 0000000..e2ddb74 --- /dev/null +++ b/FastTunel.Core.WebApi/Properties/launchSettings.json @@ -0,0 +1,27 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:55100/", + "sslPort": 44347 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "FastTunel.Core.WebApi": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:5001;http://localhost:5000" + } + } +} \ No newline at end of file diff --git a/FastTunnel.Core/Listener/ClientListenerV2.cs b/FastTunnel.Core/Listener/ClientListenerV2.cs index eb917d1..d69bde7 100644 --- a/FastTunnel.Core/Listener/ClientListenerV2.cs +++ b/FastTunnel.Core/Listener/ClientListenerV2.cs @@ -65,9 +65,27 @@ namespace FastTunnel.Core.Listener return false; } + IClientMessageHandler handler = null; try { msg = JsonConvert.DeserializeObject>(words); + //if (msg == null) + // throw new Exception("指令为空!"); + + switch (msg.MessageType) + { + case MessageType.C_LogIn: // 登录 + handler = _loginHandler; + break; + case MessageType.Heart: // 心跳 + handler = _heartHandler; + break; + case MessageType.C_SwapMsg: // 交换数据 + handler = _swapMsgHandler; + break; + default: + throw new Exception($"未知的通讯指令 {msg.MessageType}"); + } } catch (Exception ex) { diff --git a/FastTunnel.Core/Utility/Extensions/SocketExtension.cs b/FastTunnel.Core/Utility/Extensions/SocketExtension.cs index 489c0e2..30905c4 100644 --- a/FastTunnel.Core/Utility/Extensions/SocketExtension.cs +++ b/FastTunnel.Core/Utility/Extensions/SocketExtension.cs @@ -1,4 +1,5 @@ using FastTunnel.Core.Models; +using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Net.Sockets; @@ -11,7 +12,14 @@ namespace FastTunnel.Core.Extensions public static void SendCmd(this Socket socket, Message message) where T : TunnelMassage { - socket.Send(Encoding.UTF8.GetBytes(message.ToJson() + "\n")); + if (socket.Connected) + { + socket.Send(Encoding.UTF8.GetBytes(message.ToJson() + "\n")); + } + else + { + Console.WriteLine($"连接中断,消息发送失败:【{message.Content}】"); + } } } }