Merge pull request #30 from FastTunnel/xml

fixbug
This commit is contained in:
Gui.H 2021-08-03 20:27:15 +08:00 committed by GitHub
commit 59ab7e3db3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 1 deletions

View File

@ -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"
}
}
}

View File

@ -65,9 +65,27 @@ namespace FastTunnel.Core.Listener
return false;
}
IClientMessageHandler handler = null;
try
{
msg = JsonConvert.DeserializeObject<Message<JObject>>(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)
{

View File

@ -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<T>(this Socket socket, Message<T> 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}】");
}
}
}
}