Anonymous User
  Monday, 23 March 2020
  22 Replies
  3.4K 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
·
#250
Call to start server is called twice, instead of set Active := True and call Start method, set only Active := True.


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;


Doing this change, your application will work.
4 years ago
·
#251
Even with the change it still doesn't work.

Did you test this?
4 years ago
·
#252
Yes, I test your sample, check attached screenshot.

console_server.png
Attachments (1)
4 years ago
·
#253
Do you have any idea what's going on?

Thank you very much for the quick responses and commitment to helping me.
4 years ago
·
#254
Could you try to change server port? It's really weird that client connects and you don't get a notification in server side.
4 years ago
·
#255
Nothing yet...
4 years ago
·
#256
Please attach your compiled sample and your project source and I'll try later.
4 years ago
·
#258
Follow my example source code.
Attachments (1)
4 years ago
·
#259
My compiled sample wasn't possible to send because here have attach limit (2mb).
4 years ago
·
#261
Hi,

Your sample source code works well, find attached your compiled project (just compress your exe with rar and you can upload).

Sergio
Attachments (1)
4 years ago
·
#265
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.
4 years ago
·
#266
Here is my compatible executable in 3 pieces.
4 years ago
·
#269
No, there are no restrictions more than can run for a limited time.
This is a false positive, my antivirus doesn't detect nothing, from time to time I get false positives, don't worry about it.
I will install community and try to reproduce but I never hear something like this.

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.
4 years ago
·
#270
Yes, I get the same behaviour than you, I don't get any message.

Here is my compatible executable in 3 pieces.
4 years ago
·
#271
Which sgcWebSockets version do you use? seems is not latest.
If it's not latest trial, download latest, and try again.
4 years ago
·
#272
Try the following code:


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.

4 years ago
·
#273
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.
4 years ago
·
#276
Yes sorry, my mistake, I sent you another code update, did you try? The problem is that when is a console application Notifyevents property must be neNoSync, this is done automatically on source version but not trial.

Kind Regards,
Sergio

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.
4 years ago
·
#285
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
Attachments (1)
4 years ago
·
#286
Hi,

I think you experience the same problem that Marcelo, set TsgcWebSocketClient.NotifyEvents := neNoSync and will work, at least works here.
I attach a screenshot:

hwid_reset.png

Sergio

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
Attachments (1)
  • 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
· Insert · Remove
  Upload Files (Maximum 10MB)