The websocket server console application is not running events.
But same sample in VCL application is ok.
program Server;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
sgcWebSocket,
sgcWebSocket_Classes;
type
TServer = class
strict private
fServer: TsgcWebSocketServer;
procedure DoMessage(pConnection: TsgcWSConnection; const pText: string);
procedure DoConnection(pConnection: TsgcWSConnection);
public
procedure Start;
end;
{ TServer }
// it is not working???
procedure TServer.DoConnection(pConnection: TsgcWSConnection);
begin
Writeln('Servidor Conectado...');
end;
// it is not working???
procedure TServer.DoMessage(pConnection: TsgcWSConnection; const pText: string);
begin
Writeln(pText);
end;
procedure TServer.Start;
begin
Writeln('Servidor de Websocket ligado na porta 5000...');
fServer := TsgcWebSocketServer.Create(nil);
try
fServer.Port := 5000;
fServer.OnMessage := DoMessage;
fServer.OnConnect := DoConnection;
fServer.Active := True;
fServer.Start;
while fServer.Active do
begin
Sleep(10);
end;
finally
fServer.Free;
end;
end;
var
vServer: TServer;
begin
try
vServer := TServer.Create;
try
vServer.Start;
finally
vServer.Free;
end;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.