RTC Forums

Subscription => Support => Topic started by: mkurnia on June 08, 2017, 05:22:29 AM



Title: RtcDataRequest not responce value
Post by: mkurnia on June 08, 2017, 05:22:29 AM
Hi danijel,

i have problem with remote function with TRtcDataRequest, i write code in server like this:
the problem is responce from server is empty, but if i use class TPaymentSB in VCL Application, code is not problem.
where is the wrong code?

Thanks you

Code:
TPaymentSB = class
  private
    DataReq: TRtcDataRequest;
    ResJSON: RtcWideString;

  protected
    procedure DataReqBeginRequest(Sender: TRtcConnection);
    procedure DataReqDataReceived(Sender: TRtcConnection);

  public
    constructor Create(const ConnClient:TRtcHttpClient);
    destructor Destroy; override;

    function GetBalance(const ID:string; const PIN):RtcWideString;
  end;

TdmServer = class(TDataModule)
    ServerLink: TRtcDataServerLink;
    ServerModul: TRtcServerModule;
    FuncGroup: TRtcFunctionGroup;
    BalanceFunc: TRtcFunction;
    procedure BalanceFuncExecute(Sender: TRtcConnection;Param: TRtcFunctionInfo; Result: TRtcValue);
  private
    { Private declarations }

  public
    { Public declarations }
  end;
  function GetdmServer:TdmServer;

implementation

{$R *.dfm}

procedure TdmServer.BalanceFuncExecute(Sender: TRtcConnection;Param: TRtcFunctionInfo; Result: TRtcValue);
var
  PaymentSB: TPaymentSB ;
  RtcHttpClient1: TRtcHttpClient;
begin
  RtcHttpClient1 := TRtcHttpClient.Create(nil);
  with rtcClient do
  begin
    ServerAddr := sHost;
    ServerPort := sPort;
    useSSL := True;
    Blocking := True;
    useWInHTTP := True;
    AutoConnect := True;
    MultiThreaded := True;
  end;
  PaymentSB:= TPaymentSB.Create(RtcHttpClient1);
  try    
    Result.asString := PaymentSB.GetBalance(UID, PINN);
  finally
    FreeAndNil(PaymentSB);
    FreeAndNil(RtcHttpClient1);
  end;
end;

{ TPaymentSB }

constructor TPaymentSB.Create(const ConnClient:TRtcHttpClient);
begin
  DataReq := TRtcDataRequest.Create(nil);
  DataReq.Request.Host := Host;
  DataReq.Request.Method := 'POST';
  DataReq.Request.FileName := '/v1/json';
  DataReq.Request['Content-Type'] := 'application/json';
  DataReq.HyperThreading := True;
  DataReq.Client := ConnClient;
  DataReq.OnBeginRequest := DataReqBeginRequest;
  DataReq.OnDataReceived := DataReqDataReceived;
end;

destructor TPaymentSB.Destroy;
begin
  FreeAndNil(DataReq);
  inherited;
end;

procedure TPaymentSB.DataReqBeginRequest(Sender: TRtcConnection);
begin
  With TRtcDataClient(Sender) do
    Write(Request.Info.asJSON['data']);
end;

procedure TPaymentSB.DataReqDataReceived(Sender: TRtcConnection);
begin
  With TrtcDataClient(Sender) do
  If Response.Done then
  begin
    ResJSON := Read;
  end;
end;

function TPaymentSB.GetBalance(const ID, PIN: string): RtcWideString;
begin
  with DataReq do
  begin
    With Request.Info.newRecord('data') do
    begin
      asText['opcode']:= 'balance';
      asText['uid']:= ID;
      asText['pin']:= PIN;
    end;
    Post;
    if not WaitForCompletion then
      Result := 'Server Host Not Responding'
    else
      Result := ResJSON;
  end;
end;



Title: Re: RtcDataRequest not responce value
Post by: mkurnia on June 08, 2017, 05:45:09 AM
hi danijel,

i found the problem,

DataReq.HyperThreading := True;

must be

DataReq.HyperThreading := False;

Thanks You


Title: Re: RtcDataRequest not responce value
Post by: D.Tkalcec (RTC) on June 08, 2017, 05:53:56 AM
Also set rtcClient.MultiTreaded:=False to make the connection single-threaded, since you are using the connection to make a blocking call.


Title: Re: RtcDataRequest not responce value
Post by: mkurnia on June 08, 2017, 09:37:36 AM
Okey, Thank you danijel.