mirror of
https://github.com/FastTunnel/FastTunnel.git
synced 2025-02-08 02:39:29 +08:00
解决一个bug
This commit is contained in:
parent
268bd71d93
commit
c03a50c997
|
@ -9,9 +9,9 @@
|
|||
"ClientSettings": {
|
||||
"Common": {
|
||||
// 服务端公网ip, 对应服务端配置文件的 BindAddr
|
||||
"ServerAddr": "154.202.58.219",
|
||||
//"ServerAddr": "154.202.58.219",
|
||||
|
||||
//"ServerAddr": "127.0.0.1",
|
||||
"ServerAddr": "127.0.0.1",
|
||||
|
||||
// 服务端通信端口,对应服务端配置文件的 BindPort
|
||||
"ServerPort": 1271
|
||||
|
|
|
@ -176,19 +176,45 @@ namespace FastTunnel.Core.Server
|
|||
|
||||
// 将字节转换成字符串
|
||||
string words = Encoding.UTF8.GetString(buffer, 0, length);
|
||||
Message<object> msg;
|
||||
|
||||
try
|
||||
{
|
||||
msg = JsonConvert.DeserializeObject<Message<object>>(words);
|
||||
HandleWords(words, client);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex);
|
||||
_logger.LogDebug($"收到客户端 words:{words}");
|
||||
_logger.LogError($"收到客户端 words:{words}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleWords(string words, Socket client)
|
||||
{
|
||||
// 读到两个或多个指令
|
||||
var index = words.IndexOf("}{");
|
||||
if (index > 0)
|
||||
{
|
||||
var sub_words = words.Substring(0, index + 1);
|
||||
var left = words.Substring(index + 1);
|
||||
|
||||
handle(sub_words, client);
|
||||
HandleWords(left, client);
|
||||
}
|
||||
else
|
||||
{
|
||||
handle(words, client);
|
||||
}
|
||||
}
|
||||
|
||||
private void handle(string words, Socket client)
|
||||
{
|
||||
Message<object> msg = JsonConvert.DeserializeObject<Message<object>>(words);
|
||||
HandleMsg(client, msg);
|
||||
}
|
||||
|
||||
private void HandleMsg(Socket client, Message<object> msg)
|
||||
{
|
||||
_logger.LogDebug($"收到客户端指令:{msg.MessageType}");
|
||||
switch (msg.MessageType)
|
||||
{
|
||||
|
@ -196,13 +222,13 @@ namespace FastTunnel.Core.Server
|
|||
HandleLogin(client, msg);
|
||||
|
||||
// 递归调用
|
||||
ReceiveClient(client, _);
|
||||
ReceiveClient(client, null);
|
||||
break;
|
||||
case MessageType.Heart:
|
||||
client.Send(new Message<string>() { MessageType = MessageType.Heart, Content = null });
|
||||
|
||||
// 递归调用
|
||||
ReceiveClient(client, _);
|
||||
ReceiveClient(client, null);
|
||||
break;
|
||||
case MessageType.C_SwapMsg:
|
||||
var msgId = (msg.Content as string);
|
||||
|
|
Loading…
Reference in New Issue
Block a user