TWebSocketAsyncServer使用
TWebSocketAsyncServer使用
TWebSocketAsyncServer是MORMOT2异步WEBSOCKET服务端。
/// <author>cxg 2023-1-24</author> unit Unit1; interface uses mormot.net.http, mormot.net.ws.async, mormot.net.ws.core, System.Classes, Vcl.Controls, vcl.Forms, Vcl.StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } ws: TWebSocketAsyncServer; function process(Ctxt: THttpServerRequestAbstract): cardinal; public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin var port: string := '9900'; var ThreadPoolCount: Integer := 32; var KeepAliveTimeOut: Integer := 30000; ws := TWebSocketAsyncServer.Create(port, nil, nil, 'yn', ThreadPoolCount, KeepAliveTimeOut); var Protocol: TWebSocketProtocol := TWebSocketProtocol.Create('yn', ''); ws.WebSocketProtocols.Add(Protocol); ws.OnRequest := process; ws.WaitStarted(); end; function TForm1.process(Ctxt: THttpServerRequestAbstract): cardinal; begin end; end.
本文来自博客园,作者:{咏南中间件},转载请注明原文链接:https://www.cnblogs.com/hnxxcxg/p/17066187.html