You are not logged in.
Pages: 1
Use mORmot 2.0
unit uMainServer;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,
mormot.net.relay,
mormot.net.ws.core,
mormot.net.server,
mormot.net.ws.async,
mormot.net.ws.server;
type
{ TWebSocketProtocolEcho }
TWebSocketProtocolEcho = class(TWebSocketProtocolChat)
protected
procedure EchoFrame(Sender: TWebCrtSocketProcess; const Frame: TWebSocketFrame);
end;
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
FServer:TWebSocketServer;
procedure AddLog(sLog:String);
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TWebSocketProtocolEcho }
procedure TWebSocketProtocolEcho.EchoFrame(Sender: TWebCrtSocketProcess;
const Frame: TWebSocketFrame);
begin
case Frame.opcode of
focContinuation:
Form1.AddLog('Connected');
focConnectionClose:
Form1.AddLog('Disconnected');
focText,focBinary:
begin
Form1.AddLog('Echoing: '+IntToStr(length(Frame.payload))+' bytes');
SendFrame(Sender,Frame);
end;
end;
end;
{ TForm1 }
procedure TForm1.Button3Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
FServer.Suspended:=False;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
FServer.Suspended:=True;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
protocol: TWebSocketProtocolEcho;
begin
FServer := TWebSocketServer.Create('8888',nil,nil,'test',2,90000000 );
protocol := TWebSocketProtocolEcho.Create('meow','');
protocol.OnIncomingFrame := @protocol.EchoFrame;
FServer.WebSocketProtocols.Add(protocol);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
end;
procedure TForm1.AddLog(sLog: String);
begin
Memo1.Lines.Add(sLog);
end;
end.
The above code is no problem to use under windows, and the server stops after sending a few messages under deepin linux.
Offline
OK, thank you for your reply
Offline
Pages: 1