Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Internet (https://www.clubdelphi.com/foros/forumdisplay.php?f=3)
-   -   Controlar aplicación delphi desde web (https://www.clubdelphi.com/foros/showthread.php?t=60974)

azulin 21-10-2008 09:44:19

Controlar aplicación delphi desde web
 
Hola amigos foreros,

Tengo el siguiente problema y no se muy bien por donde tirar:

Necesito controlar desde una aplicación web, una aplicación delphi win32 que esté ejecutándose en una máquina remota.

Me explico mejor. He desarrollado una aplicación delphi que mediante la invocación de un prodedure lanza un visualizador de power point, y mediante otro procedure, finaliza la ejecución del visualizador.

Necesito poder accionar esos procedures desde un portal web, y para eso necesitaría alguna manera conectarme con la aplicación. Había pensado la siguiente solución, pero no lo veo claro:

Conectar la aplicación delphi con la aplicación web mediante SOAP. Es decir, generar un servidor de SOAP en mi aplicación delphi y desde la aplicación web, invocarla usando PHP. Pero no se muy si funcionaría o habría alguna otra solución..

¿Qué os parece? ¿Qué se os ocurre?

Un saludo y muchas gracias

Omega 22-10-2008 22:07:31

Se me ocurre que tu aplicación ademas pudiera ser un mini servidor HTTP.

Luego en la web y usando PHP accedes a ese servidor, con un simple file get contents.

Aquí te dejo ejemplo de como seria la parte de la aplicación. Usando un IdHTTPServer de Indy.
Código Delphi [-]
procedure TForm1.FormCreate(Sender: TObject);
begin
 IdHTTPServer1.Active := True;
end;

procedure TForm1.IdHTTPServer1CommandGet(AThread: TIdPeerThread;
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
begin
 if ARequestInfo.Document = '/iniciar' then begin
  ShowMessage('Iniciar');
 end else begin
  ShowMessage('Finalizar');
 end;
 AResponseInfo.CloseConnection := True;
end;

Y por ultimo ejemplo de como seria la parte web.
Código:

<?
# Llamar Procedure Lanzar:
file_get_contents('http://IP.DEL.PC/lanzar');

# Llamar Procedure Finalizar:
file_get_contents('http://IP.DEL.PC/finalizar');
?>

Saludos, espero te sirva.

azulin 30-10-2008 12:00:42

Me parace una buena opción. Trataré de llevarla a cabo.

Muchísimas gracias!

azulin 31-10-2008 12:00:10

Hola de nuevo,

estoy usando el siguiente código que me sugirió Omega, pero hay algunas unidades que no las encuentra: IdThreadMgr, IdThreadMgrDefault

Estoy usando Turbo Delphi 2006 e Indy 10.

No se donde puede estar el problema...


Código:

unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdBaseComponent, IdComponent, IdTCPServer, IdHTTPServer,
  StdCtrls, StrUtils, IdThreadMgr, IdThreadMgrDefault;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure IdHTTPServer1CommandGet(AThread: TIdPeerThread; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
  private
    { Private declarations }
  public
    { Public declarations }
    IdHTTPServer1: TIdHTTPServer;
  end;
var
  Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
 IdHTTPServer1.Active := True;
end;
procedure TForm1.IdHTTPServer1CommandGet(AThread: TIdPeerThread;
  RequestInfo: TIdHTTPRequestInfo; ResponseInfo: TIdHTTPResponseInfo);
begin
 if ARequestInfo.Document = '/iniciar' then begin
 ShowMessage('Iniciar');
 end else begin
 ShowMessage('Finalizar');
 end;
 AResponseInfo.CloseConnection := True;
end;
end.

Muchas gracias!!


dasda

azulin 31-10-2008 14:21:16

Ya he visto donde estaba el error. Indy 10 es ligeramente distinto a 9. Aqui está el código, probado con Turbo Delphi 2006:

Código:


unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdBaseComponent, IdComponent, IdTCPServer, IdHTTPServer,
  StdCtrls, StrUtils, IdCustomHTTPServer, IdContext;
 
type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure IdHTTPServer1CommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
  IdHTTPServer1: TIdHTTPServer;

implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
  IdHTTPServer1 := TIdHTTPServer.Create;
  IdHTTPServer1.DefaultPort := 8080;
  IdHTTPServer1.OnCommandGet := IdHTTPServer1CommandGet;
  IdHTTPServer1.Active := True;
end;
 
procedure TForm1.IdHTTPServer1CommandGet(AContext: TIdContext;
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
  strHtml: String;
begin
  // respond
  strHtml := '<h1>Servidor DEMO</h1>' +
    '<p>This is the only page you''ll get from this example.</p><hr>' +
    '<p>Request: ' + ARequestInfo.Document + '</p>' +
    '<p>Host: ' + ARequestInfo.Host + '</p>' +
    '<p>Params: ' + ARequestInfo.UnparsedParams + '</p>' +
    '<p>The headers of the request follow: <br>' +
    ARequestInfo.RawHeaders.Text + '</p>';
  AResponseInfo.ContentText := strHtml;
end;
 

end.

Luego desde el navegador... http://127.0.0.1:8080/


Ahora tengo que ver como procesar la petición y en función de esta hacer algo.

Saludos!


La franja horaria es GMT +2. Ahora son las 13:53:34.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi