// *************************************************************************** // // Delphi MVC Framework // // Copyright (c) 2010-2017 Daniele Teti and the DMVCFramework Team // // https://github.com/danieleteti/delphimvcframework // // Collaborators with this file: Ezequiel Juliano Müller (ezequieljuliano@gmail.com) // // *************************************************************************** // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // *************************************************************************** program Server; {$APPTYPE CONSOLE} uses System.SysUtils, MVCFramework.Logger, MVCFramework.Commons, Winapi.Windows, Winapi.ShellAPI, ReqMulti, Web.WebReq, Web.WebBroker, IdHTTPWebBrokerBridge, Person.Controller in 'Person.Controller.pas', App.WebModule in 'App.WebModule.pas' {AppWebModule: TWebModule} , Person in 'Person.pas'; {$R *.res} procedure RunServer(APort: Integer); var LInputRecord: TInputRecord; LEvent: DWord; LHandle: THandle; LServer: TIdHTTPWebBrokerBridge; begin Writeln('** DMVCFramework Server ** build ' + DMVCFRAMEWORK_VERSION); Writeln(Format('Starting HTTP Server on port %d', [APort])); LServer := TIdHTTPWebBrokerBridge.Create(nil); try LServer.DefaultPort := APort; LServer.Active := True; LogI(Format('Server started on port 8080', [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('Press ESC to stop the server'); LHandle := GetStdHandle(STD_INPUT_HANDLE); while True do begin Win32Check(ReadConsoleInput(LHandle, LInputRecord, 1, LEvent)); if (LInputRecord.EventType = KEY_EVENT) and LInputRecord.Event.KeyEvent.bKeyDown and (LInputRecord.Event.KeyEvent.wVirtualKeyCode = VK_ESCAPE) then break; end; finally LServer.Free; end; end; begin ReportMemoryLeaksOnShutdown := True; IsMultiThread := True; try if WebRequestHandler <> nil then WebRequestHandler.WebModuleClass := WebModuleClass; WebRequestHandlerProc.MaxConnections := 1024; RunServer(8080); except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; end.