//------------------------------------------------------------------------------ // Uint: 例子/WebSocket //------------------------------------------------------------------------------ unit websocket; interface uses System.SysUtils, System.IOUtils, System.Classes, FireHttp.Utils, FireHttp.Types, FireHttp.Classes, FireHttp.HTML, FireHttp.Path, FireHttp.Log, FireHttp.Config; type example_websocket = class(THTMLHandler) public const __PathInfo = '/websocket'; const __PathInfo_websocket_html = '/websocket.html'; const __Description = ''; protected procedure Execute; override; procedure Cleanup; override; public constructor Create(AThread: TWorkerThread); override; destructor Destroy; override; end; implementation { example_websocket } procedure example_websocket.Cleanup; begin inherited; end; constructor example_websocket.Create(AThread: TWorkerThread); begin inherited Create(AThread); {$region '设置处理者'} MultiPathInfo.Add(__PathInfo); MultiPathInfo.Add(__PathInfo_websocket_html); Description := __Description; {$endregion} end; destructor example_websocket.Destroy; begin inherited; end; procedure example_websocket.Execute; begin inherited; {$region '隐藏websocket.html文件'} if SameText(Request.PathInfo, __PathInfo_websocket_html) then begin Response.Redirect(__PathInfo); Exit; end; {$endregion} LoadHtmlFile(__PathInfo_websocket_html); end; initialization RegisterHandlerClass(example_websocket); end.