We use cookies
We use cookies and other tracking technologies to improve your browsing experience on our website, to show you personalized content and targeted ads, to analyze our website traffic, and to understand where our visitors are coming from.
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.
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; <-- commented this line
while fServer.Active do
begin
Sleep(10);
end;
finally
fServer.Free;
end;
end;
Your executable example works well here.
Any restrictions for the version being the evaluation version? We are doing tests to acquire it.
My executable example has a different size than yours. Why?
My: 9,67MB
Your: 2,57MB
Attention:
My antivirus has detected a trojan in its executable. Sorry, the print is in Portuguese.
program Server;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
sgcWebSocket,
sgcWebSocket_Classes,
sgcWebSocket_Types;
type
TServer = class
strict private
fServer: TsgcWebSocketServer;
procedure DoMessage(pConnection: TsgcWSConnection; const pText: string);
procedure DoConnection(pConnection: TsgcWSConnection);
public
procedure Start;
end;
{ TServer }
procedure TServer.DoConnection(pConnection: TsgcWSConnection);
begin
Writeln('client connected...');
end;
procedure TServer.DoMessage(pConnection: TsgcWSConnection; const pText: string);
begin
Writeln(pText);
end;
procedure TServer.Start;
begin
Writeln('Servidor de Websocket ligado na porta 3001...');
fServer := TsgcWebSocketServer.Create(nil);
try
fServer.Port := 3001;
fServer.OnMessage := DoMessage;
fServer.OnConnect := DoConnection;
fServer.NotifyEvents := neNoSync;
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.
My version is 4.3.5 TRIAL.
Which sgcWebSockets version do you use? seems is not latest.
If it's not latest trial, download latest, and try again.
I'm actually running into the same issue. I'm trying to use a DataModule to contain my components to spare the time of manually creating them. It seems to actually connect however the api events are not firing.
I have attached my project below. I have attempted to change all the Notify Events however it doesn't do anything.
I'm changing the Notify event at design time. I have cycled through all of them to test it.
Using Source Beta version: 4.3.6
Please see attached