0

I want to make a websocket server. It can run automatically as a windows service (I use module 'node-windows') and load a file dll (I use module 'ffi').

Here is code in file server.js

    var http = require("http");
    var ws = require("../../");
    var fs = require("fs");
    var ffi = require("ffi");

    var server = ws.createServer(function (connection) {
        connection.on("text", function (str) {
            var Lib = ffi.Library('add.dll', {'Add' : ['int',['int','int']]});
            var arr = str.split(":");
            var result = Lib.Add(Number(arr[0]), Number(arr[1]));
            connection.sendText(result);        
        });
    });
    server.listen(8081);

And here is code in file install.js. It will set the file server.js to run as a windows service

var Service = require('node-windows').Service;

var svc = new Service({
  name:'websocketServer',
  description: 'a simple websocket server',
  script: require('path').join(__dirname,'server.js'),
  env:{
    name: "NODE_ENV",
    value: "production"
  }
});

svc.on('install',function(){
  svc.start();
});

svc.install();

When I run it, I don't know why but the windows service stops automatically. If I don't use 'ffi', the server will run fine. Anyone can help me to solve this problem?

simon-p-r
  • 3,623
  • 2
  • 20
  • 35
Kyuubi
  • 93
  • 1
  • 8
  • Is there anything in the Event Log? – mscdex Sep 10 '16 at 03:12
  • Where is it and how can i check it? – Kyuubi Sep 10 '16 at 03:26
  • Use the Windows Event Viewer, it should be in the admin utilities (or accessible by running eventvwr.msc IIRC at least on Windows 7). – mscdex Sep 10 '16 at 03:40
  • I checked, It have 2 warnings http://i.imgur.com/52C6LyQ.png, http://i.imgur.com/IidyMQe.png and 1 error: http://i.imgur.com/pnpl6WX.png – Kyuubi Sep 10 '16 at 04:38
  • Before running it as a service run it as a normal application. Also move the `var Lib = ...` line to before the `var server = ...` so it will run faster and make it easier do debug if the error is there. – Bernardo Ramos Sep 15 '16 at 14:09

0 Answers0