I'm trying to connect to a google map service, but the app hangs in infinite loop. GoogleMapConnector.Connecting is never set to false despite of the TimeOut property I set in the constructor.
unit wmmain;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, HTTPDefs, websession, fpHTTP,
fpWeb, lHTTP;
type
{ TMainWebModule }
TMainWebModule = class(TFPWebModule)
procedure TFPWebActions0Request(Sender: TObject; ARequest: TRequest;
AResponse: TResponse; var Handled: Boolean);
procedure TFPWebActions1Request(Sender: TObject; ARequest: TRequest;
AResponse: TResponse; var Handled: Boolean);
procedure DataModuleCreate(Sender: TObject);
procedure DataModuleDestroy(Sender: TObject);
function GoogleMapConnectorOnInput(ASocket: TLHTTPClientSocket; ABuffer: pchar; ASize: integer): integer;
procedure GoogleMapConnectorOnDoneInput(ASocket: TLHTTPClientSocket);
private
{ private declarations }
GoogleMapConnector: TLHTTPClient;
ResponseBuf: String;
public
{ public declarations }
end;
var
MainWebModule: TMainWebModule;
implementation
{$R *.lfm}
const
QueryStr = 'restoran';
GoogleAPIKey = 'ABQIAAAAR16qAFe_aeUB7PXwb4ENZxRHYi30yMAYkyoiSwporea1yo0xLRTg3lf_7VNbntYiWxJvDo5nIAW_SA';
{ TMainWebModule }
procedure TMainWebModule.TFPWebActions0Request(Sender: TObject;
ARequest: TRequest; AResponse: TResponse; var Handled: Boolean);
begin
AResponse.Content := '<p>Hello, World 1!</p>';
Handled := true;
end;
procedure TMainWebModule.TFPWebActions1Request(Sender: TObject;
ARequest: TRequest; AResponse: TResponse; var Handled: Boolean);
var
StatusStr: String;
begin
ResponseBuf := '';
if GoogleMapConnector.Connect then begin
while GoogleMapConnector.Connecting do Sleep(100);
AResponse.Content := 'Respon:' +ResponseBuf;
end else begin
Str(GoogleMapConnector.Response.Status,StatusStr);
AResponse.Content := Format('HTTP %s: %s',
[StatusStr,GoogleMapConnector.Response.Reason]);
end;
Handled := true;
end;
procedure TMainWebModule.DataModuleCreate(Sender: TObject);
begin
GoogleMapConnector := TLHTTPClient.Create(Self);
with GoogleMapConnector do begin
Timeout := 10;
Host := 'http://maps.google.com';
Port := 80;
URI := Format('maps/geo?q=%s&output=json&oe=utf8&sensor=false' +
'&key=%s',[QueryStr,GoogleAPIKey]);
OnInput := @Self.GoogleMapConnectorOnInput;
OnDoneInput := @Self.GoogleMapConnectorOnDoneInput;
end;
end;
procedure TMainWebModule.DataModuleDestroy(Sender: TObject);
begin
GoogleMapConnector.Free;
end;
function TMainWebModule.GoogleMapConnectorOnInput(ASocket: TLHTTPClientSocket;
ABuffer: pchar; ASize: integer): integer;
var
TempBuf: String;
begin
SetString(TempBuf,ABuffer,ASize);
ResponseBuf := ResponseBuf + TempBuf;
end;
procedure TMainWebModule.GoogleMapConnectorOnDoneInput(
ASocket: TLHTTPClientSocket);
begin
GoogleMapConnector.Disconnect;
end;
initialization
RegisterHTTPModule('main', TMainWebModule);
end.
Btw, I'm behind a proxy. Do I need to set up anything?
Platform: i386-win32