public void HandlerMsg(FastTunnelClient cleint, Message <JObject> Msg) { var request = Msg.Content.ToObject <NewCustomerMassage>(); var interval = long.Parse(DateTime.Now.GetChinaTicks()) - long.Parse(request.MsgId.Split('_')[0]); _logger.LogDebug($"Start SwapMassage {request.MsgId} 服务端耗时:{interval}ms"); var connecter = new DnsSocket(cleint.Server.ServerAddr, cleint.Server.ServerPort); connecter.Connect(); connecter.Send(new Message <SwapMassage> { MessageType = MessageType.C_SwapMsg, Content = new SwapMassage(request.MsgId) }); _logger.LogDebug($"连接server成功 {request.MsgId}"); var localConnecter = new DnsSocket(request.WebConfig.LocalIp, request.WebConfig.LocalPort); try { localConnecter.Connect(); _logger.LogDebug($"连接本地成功 {request.MsgId}"); new SocketSwap(connecter.Socket, localConnecter.Socket, _logger, request.MsgId).StartSwap(); } catch (SocketException sex) { localConnecter.Close(); if (sex.ErrorCode == 10061) { // 内网的站点不存在或无法访问 string statusLine = "HTTP/1.1 200 OK\r\n"; string responseHeader = "Content-Type: text/html\r\n"; byte[] responseBody; responseBody = Encoding.UTF8.GetBytes(TunnelResource.Page_NoSite); connecter.Send(Encoding.UTF8.GetBytes(statusLine)); connecter.Send(Encoding.UTF8.GetBytes(responseHeader)); connecter.Send(Encoding.UTF8.GetBytes("\r\n")); connecter.Send(responseBody); connecter.Socket.Disconnect(false); connecter.Socket.Close(); return; } else { throw; } } catch (Exception) { localConnecter.Close(); throw; } }
public void HandlerMsg(FastTunnelClient cleint, Message <JObject> Msg) { var request_ssh = Msg.Content.ToObject <NewSSHRequest>(); var connecter_ssh = new DnsSocket(cleint.Server.ServerAddr, cleint.Server.ServerPort); connecter_ssh.Connect(); connecter_ssh.Send(new Message <SwapMassage> { MessageType = MessageType.C_SwapMsg, Content = new SwapMassage(request_ssh.MsgId) }); var localConnecter_ssh = new DnsSocket(request_ssh.SSHConfig.LocalIp, request_ssh.SSHConfig.LocalPort); localConnecter_ssh.Connect(); new SocketSwap(connecter_ssh.Socket, localConnecter_ssh.Socket, _logger, request_ssh.MsgId).StartSwap(); }