WebSocket 不适用于 Nexe
WebSocket not working with Nexe
我构建了一个 NodeJS 应用程序,我正在使用 Websocket 将事件发送到浏览器。现在我需要将节点应用程序捆绑到 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 模块?我已将应用程序测试为 node start,它工作正常。
这是因为 Nexe 无法支持 原生模块 。相反,我尝试了 Electron,它非常有用,并且也支持 Native 模块。
我构建了一个 NodeJS 应用程序,我正在使用 Websocket 将事件发送到浏览器。现在我需要将节点应用程序捆绑到 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 模块?我已将应用程序测试为 node start,它工作正常。
这是因为 Nexe 无法支持 原生模块 。相反,我尝试了 Electron,它非常有用,并且也支持 Native 模块。