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.

 

posted @ 2023-01-24 17:04  delphi中间件  阅读(253)  评论(0编辑  收藏  举报