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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...