首页 > 其他分享 >TWebSocketAsyncServer使用

TWebSocketAsyncServer使用

时间:2023-01-24 17:11:07浏览次数:44  
标签:end process TForm1 TWebSocketAsyncServer ws 使用 var

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.

 

标签:end,process,TForm1,TWebSocketAsyncServer,ws,使用,var
From: https://www.cnblogs.com/hnxxcxg/p/17066187.html

相关文章