protected override void OnReceived(Packet packet) { InnerTunnelPacket innerPacket = packet as InnerTunnelPacket; if (innerPacket == null) { return; } if (innerPacket.Action == 2) { FromServerManager.Instance.CloseSession(innerPacket.ServicePort, innerPacket.ClientIdentity); return; } byte[] datas = innerPacket.Read(); FromServerManager.Instance.SendData(innerPacket.ServicePort, innerPacket.ClientIdentity, datas); }
private void AgentClient_OnReceive(TCPClient client, SessionBase session, Packet packet) { InnerTunnelPacket innerPacket = packet as InnerTunnelPacket; if (innerPacket == null) { return; } ServiceClient serviceClient; string key = innerPacket.ClientIdentity.ToString() + "|" + innerPacket.ServicePort.ToString(); if (innerPacket.Action == 0) { //连接 //获取目标端口号 serviceClient = new ServiceClient(innerPacket.ServicePort, innerPacket.ClientIdentity); serviceClient.Connect(config.ServiceIP, innerPacket.ServicePort); if (serviceSessions.ContainsKey(key)) { serviceSessions[key] = serviceClient; } else { serviceSessions.Add(key, serviceClient); } return; } if (!serviceSessions.ContainsKey(key)) { return; } serviceClient = serviceSessions[key]; if (innerPacket.Action == 2) { //断开连接 serviceSessions.Remove(key); serviceClient.Disconnect(); return; } //转发数据 byte[] datas = packet.Read(); serviceClient.Send(datas); }