WebSocket无法与Nexe合作

时间:2015-09-30 14:28:28

标签: javascript node.js jxcore

我已经构建了一个NodeJS应用程序,我使用Websocket将事件发送到浏览器。现在我需要将Node Application捆绑到EXE中并发送给客户端。
我尝试了 nexe JXCore 但是nexe正在捆绑应用程序,但在我尝试运行它时会出现问题。
Websocket的JS代码是

var WebSocketServer = require('websocket').server;
var http = require('http');

var server = http.createServer(function(request, response) {
    console.log((new Date()) + ' Received request for ' + request.url);
    response.writeHead(404);
    response.end();
});
server.listen(1337, function() {
    console.log((new Date()) + ' Server is listening on port 8080');
});

wsServer = new WebSocketServer({
    httpServer: server,
    // You should not use autoAcceptConnections for production 
    // applications, as it defeats all standard cross-origin protection 
    // facilities built into the protocol and the browser.  You should 
    // *always* verify the connection's origin and decide whether or not 
    // to accept it. 
    autoAcceptConnections: false
});

wsServer.on('request', function(request) {
    var connection = request.accept(null, request.origin);
    eze.ee.on("EPIC_VALIDATING_DEVICE"  ,       function()                  {connection.sendUTF('VAlidate')});

异常堆栈如下

 nexe.js:15318
 wsServer = new WebSocketServer({
   ^

TypeError: WebSocketServer is not a function
    at Array.__dirname.call.C:\Users\Raghav Tandon\WinPos\BrowserIntegrat
ion\js\RestImpl.js.http (nexe.js:15318:12)
    at initModule (nexe.js:29:11)
    at nexe.js:31:64
    at Array.__dirname.call.C:\Users\Raghav Tandon\WinPos\BrowserIntegrat
ion\js\RestWS.js../RestImpl (nexe.js:48:20)
    at initModule (nexe.js:29:11)
    at Array.forEach (native)
    at nexe.js:39:8
    at nexe.js:46:4
    at NativeModule.compile (node.js:945:5)
    at Function.NativeModule.require (node.js:893:18)

为什么不加载 Webscocket 模块?我已经将应用程序测试为节点启动并且它正常工作。

1 个答案:

答案 0 :(得分:0)

这是因为 Nexe 无法支持原生模块。相反,我尝试了 Electron ,它就像魅力一样,也支持Native模块。