Jump to content
DidierXT

Websocket server

Recommended Posts

I'm trying to setup a Websocket server.
But I have an error when starting the server.
Seems I forgot something... maybe some internal http server?

 

unit Unit1;

interface
type
  TServer = class
  public
    procedure Run;
  end;

implementation
uses
  NodeJS.Core, SmartNJ.Server, SmartNJ.Server.websocket, NodeJS.querystring, NodeJS.url,
  System.JSON, System.DateUtils, System.Types;

{ TServer}

procedure TServer.Run;
begin
  var serveur := TNJWebSocketServer.Create;
  //  serveur.Path := '/';
  serveur.Port := 8099;
  serveur.OnAfterServerStarted :=
    procedure (sender: TObject)
    begin
      console.log('Serveur started, port:' + TNJWebSocketServer(Sender).Port.toString);
    end;
  serveur.OnClientConnected :=
    procedure (const Sender: TNJWebSocketServer; const Socket: JWsSocket)
    begin
      console.log('Client connection');
    end;
  serveur.Start;          // <====== ERROR
end;

end.

 

Share this post


Link to post
Share on other sites

I forgot the error message:

Quote

D:\Dev\NodeApp2\serveur\output\monserveur.js:4182
         throw EW3Exception.CreateFmt($New(ENJWebSocketServer),"Failed to create websocket server object, system threw exception %s with message [%s]",[TObject.ClassName(e$13.ClassType), e$13.FMessage]);
         ^
[object Object]

 

Share this post


Link to post
Share on other sites

You're definitely right for the json package.
Done in output directory:

npm install websocket

 

14 hours ago, AndreM said:

What is the actual error message? So with the %s filled in.

This is the actual message, with the % (yes strange...)

14 hours ago, AndreM said:

For now I think there are 2 reasons: port 8099 is already in use or you miss the nodejs modules

I've changed the port without success. 
Note that I have no problem with other WebServers.

 

Has some body been able to test my code?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×