PDA

Ver la Versión Completa : Aplicaciones de escritorio con control web


lookmydoom
17-12-2008, 15:04:17
Saludos colegas.

Tengo una duda, hace tiempo que he tratado de descubrir como es que algunas aplicaciones de escritorio pueden ser manejadas vía web pero sin tener instalado ningún web server.

Como ejemplo les pongo 2 programas que tienen esta característica, el uTorrent y el Rapget, este ultimo es el que mas me interesa puesto que en los archivos del programa no veo por ningun lugar algo que se asemeje a un archivo html o algo que haga referencia a esto.

El programa es muy sencillo, lo suficiente como para que use y configure alguien que no sepa nada de webs servers o algo por el estilo.

Para los que no lo conozcan el programa sirve para descargar archivos desde megaupload, rapidshare y otros, aunque esto es lo que menos me interesa.

Para poder configurar la interface web se van Settings/Connections/Web Control y veran que su configuración es muy sencilla.

Aqui les paso el link (http://www.rapget.com/en/download.html) para que lo descarguen y lo prueben.

Espero que me puedan dar alguna información que me pueda ayudar a incorporar esta opción a mis proyectos.

poliburro
17-12-2008, 16:53:25
Pues implementar un socket de escucha en tu aplicación. DE tal manera que quien se conecte a tu equipo por ese puerto pueda enviar comandos y recibir respuestas.

Saludos.

mamcx
17-12-2008, 17:24:14
Eso es MUY facil. Es algo que tengo en mi propia aplicacion.

Solo es cuestion de usar algo como Indy, Synapse, RealThinClient, RemObjects o lo que te guste y !whoila! tenes un servidor web embeido con control total ;)

La version actual la tengo con RealThinClient y estoy actualizandola con RemObjects. RTC tiene una version open source y en mi opinion le da vueltas al Indy.Ademas, podes integrar facilisimo el PHP de forma embeido y otras monerias por ahi. Tiene un desempeño de lujo y el Api es muy simple de entender (Yo nunca pude con el Indy)

pcicom
17-12-2008, 21:25:07
Saludos mamc, oye me parece muy interesante lo que comentas, me gustaria de ser posible hacer algo similar a lo que describes... No se si se pueda obtener codigo que pongas disponible, ya sea con algo mega simplon para poder entenderlo y crear algo similar a lo que realizas...

DESDE YA GRACIAS..

mamcx
17-12-2008, 22:52:09
Pues con RTC (gran parte fue copiando de los ejemplos):


procedure TfrmMain.remHomeCheckRequest(Sender: TRtcConnection);
begin
with TRtcDataServer(Sender) do
begin
if Request.FileName = '/' then
Accept;
end;//with
end;

procedure TfrmMain.remHomeDataReceived(Sender: TRtcConnection);
begin
with TRtcDataServer(Sender) do
begin
if Request.Complete then
begin
Write('<html><body>');

Write('<p><big>Servidor Sincronizador de PDA y ERP</big></p>');
Write('<p><small>PDASync Versión 1.0</small></p>');
Write('<p><a href="http://www.elmalabarista.com">El malabarista</a></p>');

Write('</body></html>');
end;//if
end;//with
end;

procedure TfrmMain.remPostFilesCheckRequest(Sender: TRtcConnection);
begin
with TRtcDataServer(Sender) do
begin
if (Request.FileName = '/Post/Archivos') and (Request.Method='POST') then
Accept;
end;//with
end;

procedure TfrmMain.remPostFilesDataReceived(Sender: TRtcConnection);
var
xml:String;
Largo:Int64;
begin
with TRtcDataServer(Sender) do
begin
if Request.Complete then
begin
try
Request.Params.AddText(Read);

xml := Request.Params.asString['xml'];
if Length(xml)=0 then
begin
raise Exception.Create('No se enviaron datos');
end;//if

xml := StringReplace(xml,'|amp;','&',[ rfReplaceAll, rfIgnoreCase ]);

dm.SaveFile(Request.Params.asString['FileName'],Request.Params);

xml := '[ACTUALIZADO]';
Largo := Length(xml);

if Request['Accept-Encoding'] = 'gzip,deflate' then
begin
xml := ZCompressStr(xml);
Response['Content-Encoding']:='deflate';
end;
Response['OriginalLength']:=IntToStr(Largo);

Response.StatusText := xml;
write(xml);
except
on E:Exception do
begin
msg('ERR!'+e.Message);
Response.Status(500,E.Message);
Write('Status 500: '+ E.Message);
end;
end;
end;//if
end;//with
end;

procedure TfrmMain.WebServerConnecting(Sender: TRtcConnection);
begin
if not Sender.inMainThread then
Sender.Sync(WebServerConnecting)
else
begin
CS.Enter;
try
Inc(CliCnt);
with Sender do
begin
Msg('++++ '+PeerAddr+':'+PeerPort+' ['+IntToStr(CliCnt)+' open]');
end;//with

tray.IconIndex := 2;
finally
CS.Leave;
end;//try
end;//if
end;

procedure TfrmMain.WebServerDataIn(Sender: TRtcConnection);
begin
if not Sender.inMainThread then
Sender.Sync(WebServerDataIn)
else
begin
TotalDataIn:=TotalDataIn+Sender.DataIn;
BarraEstado.SimpleText:='Recibiendo ' + IntToStr(TotalDataIn)+' + '+IntToStr(TotalDataOut)+' bytes';
end;//if
end;

procedure TfrmMain.WebServerDataOut(Sender: TRtcConnection);
begin
if not Sender.inMainThread then
Sender.Sync(WebServerDataOut)
else
begin
TotalDataOut:=TotalDataOut+Sender.DataOut;
BarraEstado.SimpleText:='Enviando ' + IntToStr(TotalDataIn)+' + '+IntToStr(TotalDataOut)+' bytes';
end;
end;

procedure TfrmMain.WebServerDisconnect(Sender: TRtcConnection);
begin
if not Sender.inMainThread then
Sender.Sync(WebServerDisconnect)
else
begin
CS.Enter;
try
Dec(CliCnt);
with Sender do
Msg('---- '+PeerAddr+':'+PeerPort+' ['+IntToStr(CliCnt)+' close]');

if CliCnt=0 then
begin
tray.IconIndex := 7;
end;//if
finally
CS.Leave;
end;//try
end;//if
end;

procedure TfrmMain.WebServerInvalidRequest(Sender: TRtcConnection);
begin
if not Sender.inMainThread then
Sender.Sync(WebServerInvalidRequest)
else
begin
with TRtcDataServer(Sender) do
begin
Msg('ERR! '+PeerAddr+' > "'+Request.Method+' '+Request.FileName+'" > Invalid Request: Header size limit exceeded.');

Response.Status(400,'Bad Request');
Write('Status 400: Bad Request');
end;//with
end;//if
end;

procedure TfrmMain.WebServerListenError(Sender: TRtcConnection; E: Exception);
begin
if not Sender.inMainThread then
Sender.Sync(WebServerListenError,E)
else
begin
Msg('ERR! ' + E.Message);
end;
end;

procedure TfrmMain.WebServerListenLost(Sender: TRtcConnection);
begin
if not Sender.inMainThread then
Sender.Sync(WebServerListenLost)
else
begin
Msg('Perdida comunicación');
btnRun.Action := actRun;
end;

end;

procedure TfrmMain.WebServerListenStart(Sender: TRtcConnection);
begin
if not Sender.inMainThread then
Sender.Sync(WebServerListenStart)
else
begin
Msg('Servidor iniciado. Escuchando en puerto ' + WebServer.ServerPort);
end;
end;

procedure TfrmMain.WebServerListenStop(Sender: TRtcConnection);
begin
if not Sender.inMainThread then
Sender.Sync(WebServerListenStart)
else
begin
Msg('Servidor detenido');
btnRun.Action := actRun;
end;
end;

procedure TfrmMain.WebServerRequestAccepted(Sender: TRtcConnection);
begin
if not Sender.inMainThread then
Sender.Sync(WebServerRequestAccepted)
else
begin
with TRtcDataServer(Sender) do
begin
Msg(Request.Method+':'+PeerAddr+' > "' + Request.URI+'"');
end;//with
end;//if
end;

procedure TfrmMain.WebServerRequestNotAccepted(Sender: TRtcConnection);
begin
if not Sender.inMainThread then
Sender.Sync(WebServerRequestNotAccepted)
else
begin
// Anything that comes this far is not acceptable by any DataProvider component.
with TRtcDataServer(Sender) do
begin
Msg('BAD! '+PeerAddr+' > "'+Request.Method+' '+Request.FileName+'" > Method "'+Request.Method+'" not supported.');

Response.Status(400,'Bad Request');
Write('Status 400: Bad Request');

Disconnect;
end;//with
end;//if
end;

lookmydoom
18-12-2008, 14:17:01
Bueno gracias a poliburro y mamcx por las ideas y sobre todo el codigo de ejemplo, yo estaba haciendo un pequeño experimento con Indy ya que no encontré el opensource de RTC y sus versiones de pago pues estan fuera del alcance de mis bolsillos. :(

Por otra parte aplicación que estaba haciendo con Indy, mas concretamente con el componente idHTTPServer hago un mini web server el cual logra servir un archivo index.html exitosamente.

Mi duda seria; si tuviera un form con 2 inputs en el index.html, como lograría traspasar los valores de dichos inputs a mi aplicación. :confused: