Skip to content

Commit

Permalink
slightly fixed rest-websockets sample
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud Bouchez committed Mar 6, 2023
1 parent e9f5d05 commit ef3e0d7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
37 changes: 18 additions & 19 deletions ex/rest-websockets/restws_chatserver.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ program restws_chatserver;

uses
{$I mormot.uses.inc} // use FastMM4 on older versions of Delphi
SysUtils,
Classes,
sysutils,
classes,
mormot.core.base,
mormot.core.os,
mormot.core.log,
Expand All @@ -29,18 +29,19 @@ type
fConnected: array of IChatCallback;
public
// IChatService methods
procedure Join(const pseudo: string; const callback: IChatCallback);
procedure BlaBla(const pseudo,msg: string);
procedure Join(const {%H-}pseudo: string; const callback: IChatCallback);
procedure BlaBla(const pseudo, msg: string);
// IServiceWithCallbackReleased method
procedure CallbackReleased(const callback: IInvokable; const interfaceName: RawUTF8);
procedure CallbackReleased(
const callback: IInvokable; const interfaceName: RawUTF8);
end;

procedure TChatService.Join(const pseudo: string; const callback: IChatCallback);
begin
InterfaceArrayAdd(fConnected,callback);
end;

procedure TChatService.BlaBla(const pseudo,msg: string);
procedure TChatService.BlaBla(const pseudo, msg: string);
var
i: PtrInt;
begin
Expand All @@ -52,7 +53,8 @@ begin
end;
end;

procedure TChatService.CallbackReleased(const callback: IInvokable; const interfaceName: RawUTF8);
procedure TChatService.CallbackReleased(
const callback: IInvokable; const interfaceName: RawUTF8);
begin
if interfaceName = 'IChatCallback' then
InterfaceArrayDelete(fConnected,callback);
Expand All @@ -61,27 +63,24 @@ end;

procedure Run;
var
HttpServer: TSQLHttpServer;
Server: TSQLRestServerFullMemory;
HttpServer: TRestHttpServer;
Server: TRestServerFullMemory;
begin
Server := TSQLRestServerFullMemory.CreateWithOwnModel([]);
Server := TRestServerFullMemory.CreateWithOwnModel([]);
try
Server.CreateMissingTables;
Server.ServiceDefine(TChatService, [IChatService], sicShared).
SetOptions([], [optExecLockedPerInterface]). // thread-safe fConnected[]
ByPassAuthentication := true;
HttpServer := TSQLHttpServer.Create('8888', [Server], '+', WEBSOCKETS_DEFAULT_MODE);
HttpServer := TRestHttpServer.Create(
'8888', [Server], '+', WEBSOCKETS_DEFAULT_MODE);
try
HttpServer.WebSocketsEnable(Server, CHAT_TRANSMISSION_KEY)^.
SetFullLog; // full verbose logs for this demo
TextColor(ccLightGreen);
writeln('WebSockets Chat Server running on localhost:8888'#13#10);
TextColor(ccWhite);
writeln('Please compile and run restws_chatlient'#13#10);
TextColor(ccLightGray);
writeln('Press [Enter] to quit'#13#10);
TextColor(ccCyan);
readln;
ConsoleWrite('WebSockets Chat Server running on localhost:8888'#13#10, ccLightGreen);
ConsoleWrite('Please compile and run restws_chatclient'#13#10, ccWhite);
ConsoleWrite('Press [Enter] to quit'#13#10);
ConsoleWaitForEnterKey;
finally
HttpServer.Free;
end;
Expand Down
2 changes: 1 addition & 1 deletion src/mormot.commit.inc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
'2.0.5026'
'2.0.5027'

0 comments on commit ef3e0d7

Please sign in to comment.