delphimvcframework/samples/basicdemo_server/BasicDemo.dpr

115 lines
3.0 KiB
ObjectPascal
Raw Normal View History

2013-10-29 16:51:16 +01:00
program BasicDemo;
{$APPTYPE CONSOLE}
2013-10-29 16:51:16 +01:00
uses
System.SysUtils,
Web.WebReq,
Web.WebBroker,
IdHTTPWebBrokerBridge,
MVCFramework.REPLCommandsHandlerU,
MVCFramework.Logger,
2013-10-29 16:51:16 +01:00
WebModuleUnit1 in 'WebModuleUnit1.pas' {WebModule1: TWebModule} ,
App1MainControllerU in 'App1MainControllerU.pas';
{$R *.res}
2013-10-29 16:51:16 +01:00
procedure RunServer(APort: Integer);
var
lServer: TIdHTTPWebBrokerBridge;
lCustomHandler: TMVCCustomREPLCommandsHandler;
lCmd, lStartupCommand: string;
2013-10-29 16:51:16 +01:00
begin
if ParamCount >= 1 then
lStartupCommand := ParamStr(1)
else
2017-05-25 16:57:49 +02:00
lStartupCommand := 'start';
lCustomHandler := function(const Value: String; const Server: TIdHTTPWebBrokerBridge; out Handled: Boolean): THandleCommandResult
begin
Handled := False;
Result := THandleCommandResult.Unknown;
// Write here your custom command for the REPL using the following form...
// ***
// Handled := False;
// if (Value = 'apiversion') then
// begin
// REPLEmit('Print my API version number');
// Result := THandleCommandResult.Continue;
// Handled := True;
// end
// else if (Value = 'datetime') then
// begin
// REPLEmit(DateTimeToStr(Now));
// Result := THandleCommandResult.Continue;
// Handled := True;
// end;
end;
// Writeln(Format('Starting HTTP Server or port %d', [APort]));
2013-10-29 16:51:16 +01:00
LServer := TIdHTTPWebBrokerBridge.Create(nil);
try
LServer.DefaultPort := APort;
LogI(Format('Server started on port %d', [APort]));
{ more info about MaxConnections
http://www.indyproject.org/docsite/html/frames.html?frmname=topic&frmfile=TIdCustomTCPServer_MaxConnections.html }
LServer.MaxConnections := 0;
{ more info about ListenQueue
http://www.indyproject.org/docsite/html/frames.html?frmname=topic&frmfile=TIdCustomTCPServer_ListenQueue.html }
LServer.ListenQueue := 200;
WriteLn('Write "quit" or "exit" to shutdown the server');
repeat
// TextColor(RED);
// TextColor(LightRed);
Write('-> ');
// TextColor(White);
if lStartupCommand.IsEmpty then
ReadLn(lCmd)
else
begin
lCmd := lStartupCommand;
lStartupCommand := '';
WriteLn(lCmd);
end;
case HandleCommand(lCmd.ToLower, LServer, lCustomHandler) of
THandleCommandResult.Continue:
begin
Continue;
end;
THandleCommandResult.Break:
begin
Break;
end;
THandleCommandResult.Unknown:
begin
REPLEmit('Unknown command: ' + lCmd);
end;
end;
until false;
2013-10-29 16:51:16 +01:00
finally
LServer.Free;
end;
end;
begin
ReportMemoryLeaksOnShutdown := True;
try
if WebRequestHandler <> nil then
WebRequestHandler.WebModuleClass := WebModuleClass;
WebRequestHandlerProc.MaxConnections := 1024;
2017-05-25 16:57:49 +02:00
RunServer(8080);
2013-10-29 16:51:16 +01:00
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
2014-09-05 12:47:40 +02:00
end;
2013-10-29 16:51:16 +01:00
end.