Forward traffic between servers. HTTP Chat sample

Maybe it helps to somebody with the same problem. I need to forward the traffic from one server in public ip to a private, VPN connected server. The solution is very simple, actually. Thanks to the @evgeny help.

he trick is change the path to any name (I choose forward)

And the in the server with port 8099 (not in the picture but is a standard server with port 8099 and json channel) do this.

procedure THTTPChatServerMainForm.ROServerCustomResponseEvent(const aTransport: IROHTTPTransport; const aRequestStream,
  aResponseStream: TStream; const aResponse: IROHTTPResponse; var aHandled: Boolean);
begin
  if pos('/forward',aTransport.PathInfo) = 1 then
  begin
    (ROIndyHTTPChannel1 as IROTransportChannel).Dispatch(aRequestStream, aResponseStream);
    aHandled := True;
  end;
end;

The ROIndyHTTPChannel have target url as http://127.0.0.1:9000/json

The event manager also WAE!

Project source can be downloaded here.

Maybe with some adjustments can be included in RemObjects samples in a near future.

HTH

P.S. If you don´t care can please vote my requirements of Delphi ARM Linux compiler :wink:

https://quality.embarcadero.com/browse/RSP-13370

2 Likes

Just add a easy way to allow to use different channels ranging the path

procedure THTTPChatServerMainForm.ROServerCustomResponseEvent(const aTransport: IROHTTPTransport; const aRequestStream,
  aResponseStream: TStream; const aResponse: IROHTTPResponse; var aHandled: Boolean);
var
  message_str: string;
begin
  // 6/16/2020 10:42 G.G -> accepts forward path following convention
  // forward_soap -> soap message
  // forward_bin  -> bin message
  // forward_json -> json message
  if pos('/forward',aTransport.PathInfo) = 1 then
  begin
    message_str := aTransport.PathInfo.Substring('/forward_'.Length, aTransport.PathInfo.Length);
    ForwardChannel.TargetUrl := 'http://127.0.0.1:9000/'+ message_str;
    (ForwardChannel as IROTransportChannel).Dispatch(aRequestStream, aResponseStream);
    aHandled := True;
  end;
end;

as result have two client app using different channels

HTH

best regards.

1 Like