You are not logged in.
Pages: 1
The side of a WebSockets server, is there any event or method to report when a client is connected and disconnected?
As an example to demonstrate in a StringList ...
Server code so far:
private
ModeloServicos : TSQLModel;
ServidorServicos : TSQLRestServerFullMemory;
HTTPServer : TSQLHttpServer;
...
procedure TobjMain.InicializarServicos;
var au : TSQLAuthUser;
begin
ModeloServicos := TSQLModel.Create([],_CONST_ROOT_NAME);
ServidorServicos := TSQLRestServerFullMemory.Create(ModeloServicos,'test.json',false,true);
ServidorServicos.ServiceDefine(TATWLicensingModule, [IATWLicModule], sicPerSession);
HTTPServer := TSQLHttpServer.Create('8889',[ServidorServicos],'+',useBidirSocket);
HTTPServer.WebSocketsEnable(ServidorServicos, _CONST_ENCRIPT).Settings.SetDefaults();
end;
Tanks
Offline
I've introduced TWebSocketProcessSettings.OnClientConnected and OnClientDisconnected events.
See http://synopse.info/fossil/info/e2e8eb68ef
But I'm not sure if it is very useful...
IMHO you should better handle it at TSQLRestServer level, using authentication and a mORMot session.
BTW Settings.SetDefaults is already done internally by default: no need to write it again.
Offline
I was with a version that did not have such an implementation.
Thanks for the answer ...
But do not quite understand your cue to use TSQLRestServer to bring me client connection data (IP, username, SessionID, etc), it is possible the server side (with WebSockets)?
I found nothing in the sample code ...
begin
ModeloServicos := TSQLModel.Create([],_CONST_ROOT_NAME);
ServidorServicos := TSQLRestServerFullMemory.Create(ModeloServicos,'test.json',false,true);
ServidorServicos.ServiceDefine(TATWLicensingModule, [IATWLicModule], sicPerSession);
HTTPServer := TSQLHttpServer.Create('8889',[ServidorServicos],'+',useBidirSocket);
// activa o WebSockets para o protocolo de TWebSocketProtocolBinary , com uma chave de encriptação
HTTPServer.WebSocketsEnable(ServidorServicos, _CONST_ENCRIPT).Settings.SetFullLog;
// f := CurrentServiceContext;
HTTPServer.WebSocketsEnable(ServidorServicos, _CONST_ENCRIPT).Settings.OnClientConnected := evntLogado;
HTTPServer.WebSocketsEnable(ServidorServicos, _CONST_ENCRIPT).Settings.OnClientDisconnected := evntLogout;
end;
procedure TobjMain.evntLogado(Sender: TObject);
begin
//Ideal bring the customer's name, IP address, session ID ....
objLstBox.AddItem('Client connected',Self);
end;
procedure TobjMain.evntLogout(Sender: TObject);
begin
//Ideal bring the customer's name, IP address, session ID ....
objLstBox.AddItem('Client disconnected',Self);
end;
Last edited by douglasmmm (2015-05-26 18:58:10)
Offline
From TWebSocketProcessSettings.OnClientConnected and OnClientDisconnected events you would not be able to get those information.
But from TSQLRestServer, you could use the ServiceContext threadvar.
See http://synopse.info/files/html/Synopse% … l#TITL_107
Offline
Pages: 1