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 @   delphi中间件  阅读(272)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
历史上的今天:
2021-01-24 微服务概念讲解
2021-01-24 使用multipart打造rest粗接口
点击右上角即可分享
微信分享提示