public void Route(RequestContext requestContext) { if (requestContext.CurrentSocket.Connected && requestContext.IsValid()) { RouteData routeData = FindMatchRouteData(requestContext); if (routeData != null) { Socket connectSocket = SocketUtil.Connect(routeData.TargetHostName, routeData.TargetPort); connectSocket.Send(requestContext.RequestMessageByte); byte[] recieveMessage = SocketUtil.Receive(connectSocket); requestContext.CurrentSocket.Send(recieveMessage); } } }
private RouteData FindMatchRouteData(RequestContext requestContext) { return this.RouteTable.SingleOrDefault(item => item.SourceHostName.Equals(requestContext.RequestMessageHostName, StringComparison.CurrentCultureIgnoreCase) && item.SourcePort == requestContext.Port); }