Skip to content

Commit

Permalink
enhance bad network tolerence.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmoonlight committed Jun 30, 2019
1 parent 858ac2d commit 0382686
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/NSmartProxy.ServerHost/ServerHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static void Main(string[] args)
string msg = "Another instance of the program is running.It may cause fatal error.";
//Logger.Error(msg, new Exception(msg));
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.Write(msg);
Console.WriteLine(msg);
//return;
//Console.ForegroundColor = default(ConsoleColor);
}
Expand Down
12 changes: 3 additions & 9 deletions src/NSmartProxy/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,22 +389,19 @@ private async Task ProcessHeartbeatProtocol(TcpClient client)
int heartBeatLength = 2;
byte[] appRequestBytes = new byte[heartBeatLength];
int resultByte = await nstream.ReadAsync(appRequestBytes, 0, appRequestBytes.Length, Global.DefaultConnectTimeout);
//Server.Logger.Debug("appRequestBytes received.");
if (resultByte < 1)
{
CloseClient(client);
return;
}
//1.2 响应ACK
await nstream.WriteAndFlushAsync(new byte[] { 0x01 }, 0, 1);

int clientID = StringUtil.DoubleBytesToInt(appRequestBytes[0], appRequestBytes[1]);
#if DEBUG
//Server.Logger.Debug($"Now processing {clientID}'s Heartbeat protocol....");
#endif
ServerContext.ClientConnectCount += 1;
//2.更新最后更新时间
if (ServerContext.Clients.ContainsKey(clientID))
{
//2.2 响应ACK
await nstream.WriteAndFlushAsync(new byte[] { 0x01 }, 0, 1);
ServerContext.Clients[clientID].LastUpdateTime = DateTime.Now;
}
else
Expand Down Expand Up @@ -438,10 +435,7 @@ private async Task<bool> ProcessAppRequestProtocol(TcpClient client, bool IsReco
return false;
}

//if (IsReconnect) 因为加入了始终校验的机制,取消重连规则
//{
ServerContext.CloseAllSourceByClient(clientIdFromToken);
// }

//1.3 获取客户端请求数
int configRequestLength = 3;
Expand Down
2 changes: 1 addition & 1 deletion src/NSmartProxyClient/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"ProviderPort": "19974", //反向连接的端口
"ProviderConfigPort": "12308", //配置服务的端口
//"ProviderAddress": "47.90.204.25", //配置服务的地址,可以是域名(eg.:www.tmoonlight.com)也可以是ip(eg.:211.54.5.4)
"ProviderAddress": "127.0.0.1",
"ProviderAddress": "192.168.0.106",
//"ProviderAddress": "124.116.157.31",

//反向代理客户端,可以配置多个
Expand Down

0 comments on commit 0382686

Please sign in to comment.