View Single Post
  #8  
Old 9th October 2019, 03:26 AM
chris chris is offline
Junior Member
 
Join Date: May 2015
Posts: 16
Default

I've posted a sample to https://www.onyxsoftware.co.uk/OSNXC...rarySample.zip

There's a windows server that must be running first, it needs to be able to connect to a running NexusDB server over TCPIP.

There's also a client apk to install on your device.

The code for both is:

Server

Code:
procedure TfrmServer.ck1Click(Sender: TObject);
begin
  osnxsrvr1.HTTPServer.HTTPPort := StrToInt(txtPort.Text);
  osnxsrvr1.HTTPServer.SSLPort := StrToInt(txtSSLPort.Text);
  if ck1.Checked then
    osnxsrvr1.HTTPServer.StartListening()
  else
    osnxsrvr1.HTTPServer.StopListening();
end;

procedure TfrmServer.cknxServerStatusClick(Sender: TObject);
begin
  nxWinsockTransport1.ServerName := txtDBServerIP.Text;
  nxWinsockTransport1.Port := StrToInt(txtDBServerPort.Text);
  nxWinsockTransport1.Active := true;
  cknxServerStatus.Checked := nxWinsockTransport1.Active;
end;

procedure TfrmServer.osnxsrvr1CreateHTTPServer(Sender: TObject);
var
  SSLFolder : String;
begin
  //We support Indy and RTC but you can create wrappers for your own provider
  osnxsrvr1.HTTPServer := TOSnxIndyHTTPServer.Create();
  //Set the port that will be used on the lan (i.e. no ssl)
  osnxsrvr1.HTTPServer.HTTPPort := 90;
  //Set the port that the mobile devices will use when connecting outside of the lan, port forwarding will be needed
  osnxsrvr1.HTTPServer.SSLPort := 500;
  //We support Deflate and GZip
  osnxsrvr1.HTTPServer.Deflate := true;
  //This is SSL for Indy, RTC is slightly different and requires a third party SSL provider
  SSLFolder := ExtractFileDir(Application.ExeName);
  SSLFolder := TPath.Combine(SSLFolder,'IndySSL');
  //If this fails then the certificates have probably expired
  osnxsrvr1.HTTPServer.SetSSLFiles(TPath.Combine(SSLFolder,'ca.root.pem'),
                                    TPath.Combine(SSLFolder,'cert.pem'),
                                    TPath.Combine(SSLFolder,'key.pem'),
                                    'abcd');

  //Mobile clients need to authenticate to the HTTP server so add a user here
  osnxsrvr1.Users.Add(TOSUser.Create('Chris','CloudCarpetFence'));

end;
and for the client

Code:
procedure TfrmClientMain.cmdRunSQLClick(Sender: TObject);
begin
  if txtAliasName.Text = '' then
  begin
    ShowMessage('Please enter a DB Alias');
    exit;
  end;

  cmdRunSQL.Enabled := false;
  DBConnection.ServerAddress := txtServerAddress.Text;
  DBConnection.ServerUserName := txtUserName.Text;
  DBConnection.ServerPassword := txtPassword.Text;

  Session.AliasName := txtAliasName.Text;
  Qry.SQL.Clear();
  Qry.SQL.Add(mmoSQL.Text);
  Qry.Open(
    procedure(AQry:TOSNXQuery;ASuccess:boolean;E:Exception)
    begin
      cmdRunSQL.Enabled := true;
      if not ASuccess then
        ShowMessage(E.Message);
    end);
end;
Please let me know if you have any problems or further questions.

Cheers

Chris