Jump to content
Sign in to follow this  
bilcan

Websocket Server Start Error

Recommended Posts

unit Unit1;

interface

uses
  NodeJS.Core,
  System.Types, System.Types.Convert, System.Objects, System.Device.Storage,
  System.Streams, System.Reader, System.Writer, System.JSON, System.IOUtils,
  SmartNJ.System, SmartNJ.Device.Storage, SmartNJ.Application,
  SmartNJ.Server.WebSocket;

type
  TNodeProgram = class(TObject)
  private
    FServer:    TNJWebSocketServer;
  protected
    procedure   HandleServerStarted(Sender: TObject);
  public
    procedure   Execute;
    constructor Create; virtual;
    destructor  Destroy; override;
  end;

implementation

constructor TNodeProgram.Create;
begin
  inherited Create;
  FServer := TNJWebSocketServer.Create;
  FServer.Port := 3500;
  FServer.OnAfterServerStarted := HandleServerStarted;
end;

destructor TNodeProgram.Destroy;
begin
  FServer.free;
  inherited;
end;

procedure TNodeProgram.Execute;
begin
  FServer.Start();
end;

procedure TNodeProgram.HandleServerStarted(Sender: TObject);
begin
  WritelnF('Server listening on port %d', [FServer.port]);
end;

end.

 

And I got following error message. (I installed nodejs websocket)

 

[info] Program starting

E:\SmartMobile\Server\output\Server.js:5076
         throw EW3Exception.CreateFmt($New(ENJWebSocketServer),"Failed to create websocket server object, system threw exception %s with message [%s]",[TObject.ClassName(e$11.ClassType), e$11.FMessage]);
         ^
[object Object]
[info] Program stopped

 

Share this post


Link to post
Share on other sites

Have you installed the websocket package in the output directory?
You write "I installed nodejs websocket" but it has to be the "ws" package and it has to be in the same folder as the project compiled file.

1. Open shell (CMD) and cd to the project folder
2. CD into the output folder (just compile to create it)
3. in the shell window, type "npm install ws". Npm (node package manager) will now download and place the ws (websocket) package files relative to the compiled *.js file (your compiled project file).
4. then run the project

Note: To build a dependency file, add the "--save" param to the NPM command, it will then create a packages file. This is cool when you want to push your code to amazon etc. because node will then notice this and install all the dependencies in one-go :)

I tested your code and it worked on the first try after i installed the ws library


 

websocket.png

Share this post


Link to post
Share on other sites

Its actually one of the coolest things about node.js!

Node also has clang (c++ compiler) built-in, so if you use native packages it will actually re-compile node.js on the spot (!)
But the majority of modules are raw JS and can be safely copied between systems.

So you can write a server on windows, and just copy it to linux without any change :)

Share this post


Link to post
Share on other sites

[info] Program starting
*** Cannot create process "\node.exe" --no-warnings --stack-size=1200 "C:\sms3\Projects\Featured Demos\Node.js\Websocket Server Example\output\WebSocketServer.js". [2] The system cannot find the file specified
[info] Program stopped



I have latest version node

I have installed ws folder in output folder as suggested in file. Not sure how to proceed
 

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.

Sign in to follow this  

×
×
  • Create New...