RTC Forums
November 23, 2024, 07:19:57 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: RtcDataRequest not responce value  (Read 4674 times)
mkurnia
RTC Expired
*
Posts: 21


« 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;

Logged
mkurnia
RTC Expired
*
Posts: 21


« Reply #1 on: June 08, 2017, 05:45:09 AM »

hi danijel,

i found the problem,

DataReq.HyperThreading := True;

must be

DataReq.HyperThreading := False;

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


« Reply #2 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.
Logged
mkurnia
RTC Expired
*
Posts: 21


« Reply #3 on: June 08, 2017, 09:37:36 AM »

Okey, Thank you danijel.
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 17 queries.