RTC Forums
November 24, 2024, 02:00:53 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: Connection Host to Host  (Read 5120 times)
mkurnia
RTC Expired
*
Posts: 21


« on: November 14, 2015, 05:25:39 AM »

Hi Danijel,

Continuing my question a few days ago, I'm making an application as shown below:



rules:
The client can only send a request to the server 1 then requests from client forwarded to the server 2. if it is getting the appropriate request, the server 1 sends back to the client.

I've made a connection between the client application and the server 1 goes well, but a request from a client is forwarded to the server 2 can not be done because I can not make the components rtchttpclient on datamodule server runtime.

how so that my application can work as planned?
Logged
mkurnia
RTC Expired
*
Posts: 21


« Reply #1 on: November 14, 2015, 07:40:36 AM »

I followed this article and successful.

my code is safe?
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #2 on: November 14, 2015, 08:20:37 AM »

If your Server is single-threaded, then yes. Your Server should work this way. But if your Server is Multi-Threaded, then you should either set the HyperThreading property on the TRtcClientModule component to TRUE (so the component can be used from multiple threads at the same time), or use a separate TRtcHttpClient and TRtcClientModule instance for every thread (either by creating a pool of TRtcHttpClient and TRtcClientModule components or by creating and destroying the components on-the-fly. If you want to create and destroy the components on-the-fly and you will be using the component in blocking mode, then I also recommend setting the Blocking property on the TRtcHttpClient component to TRUE (so the component will be using blocking sockets instead of non-blocking).

Best Regards,
Danijel Tkalcec
Logged
mkurnia
RTC Expired
*
Posts: 21


« Reply #3 on: November 14, 2015, 08:58:43 AM »

this my code, runtime component for rtchttpclient and RtcClientModule.

Code:
procedure TdmServer.CekBalanceFuncExecute(Sender: TRtcConnection;
  Param: TRtcFunctionInfo; Result: TRtcValue);
var
  rtcClient: TRtcHttpClient;
  rtcClientModul: TRtcClientModule;
  myRemote: TMyRemoteClass;
begin
  rtcClient := TRtcHttpClient.Create(nil);
  rtcClientModul := TRtcClientModule.Create(nil);
  try
    with rtcClient do
    begin
      ServerAddr := sIP;
      ServerPort := sPort;
      useSSL := True;
    end;
    with rtcClientModul do
    begin
      ModuleFileName := sModFilNam;
      DataFormat := fmt_XMLRPC;
      Client := rtcClient;
    end;
    if Param.asInteger['PIN'] = 1234 then
    begin
      rtcClient.Disconnect;
      rtcClient.Connect();
      myRemote := TMyRemoteClass.Create(rtcClientModul);
      try
        Result.asArray := myRemote.GetBalance(sUID, sPIN);
      finally
        FreeAndNil(myRemote);
      end;
    end
    else
    begin
      Result.asString := 'You Not Have authority for access!';
    end;
  finally
    FreeAndNil(rtcClient);
    FreeAndNil(rtcClientModul);
  end;
end;

Thanks you Danijel
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #4 on: November 14, 2015, 10:30:54 AM »

That should work. The only thing I would add, since you are using SSL (and I gess the Server should work with a lot of Clients at the same time), is to set the useWinHTTP property on the TRtcHttpClient component to TRUE, because the WinInet API (used when useSSL=True but useWInHTTP=False) has a limit of 3 active connections per outgoing Address, while the WinHTTP API (used when useWInHTTP=True) does NOT have an outgoing connection limit.

PS. I guess the "GetBalance" method on your "TMyRemoteClass" is implemented based on the example code from the FAQ, so the TRtcArray object returned from the method is destroyed in the "TMyRemoteClass" destructor to avoid a memory leak, since assigning a TRtcArray to the "asArray" property creates a copy of the original TRtcArray object and assigns that copy.

Best Regards,
Danijel Tkalcec
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.024 seconds with 16 queries.