Anonymous User
  Monday, 23 March 2020
  22 Replies
  4.2K Visits
  Subscribe
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.
4 years ago
·
#287
I swear I did set it to `neNoSync` after reading through this post. Not sure why it works now all of a sudden....

Sorry for wasting your time. Have a good night.
4 years ago
·
#288
No problem!

Sergio

I swear I did set it to `neNoSync` after reading through this post. Not sure why it works now all of a sudden....

Sorry for wasting your time. Have a good night.
  • Page :
  • 1
  • 2
There are no replies made for this post yet.
Submit Your Response
Upload files or images for this discussion by clicking on the upload button below.
Supported: gif,jpg,png,jpeg,zip,rar,pdf,pas,dfm,dpr,dproj,dpk
· Insert · Remove
  Upload Files (Maximum 10MB)