node.js - Socket.IO 连接后节点应用程序退出
问题描述
所以已经阅读了这两个类似的问题
在第一个(也是唯一一个)Socket.IO 连接之后,我的 Node.js 服务器应用程序立即退出。但并非每次,它似乎都是随机发生的,这使得故障排除更加困难。
在 Windows 10 中安装 Node v 10.16.3。
任何 Node.js 专家都可以建议一些故障排除步骤吗?
这是我的节点服务器应用程序的相关部分
var nodemailer = require('nodemailer');
var sgTransport = require('nodemailer-sendgrid-transport');
const os = require('os');
var exec = require('exec');
var child_process = require('child_process');
console.log(os.release());
var options = {
auth: {
api_key: 'my key here'
}
}
var mailer = nodemailer.createTransport(sgTransport(options));
//socket.IO code
var port = 3000;
var sys = require('util');
var express = require('express');
var app = express();
app
.use(express.static(__dirname + '/public'))
.get('/', function (req, res) {
res.write('API');
res.send('Hello World');
});
var server = app.listen(port);
var io = require('socket.io');
var sockIO = io.listen(server);
//sockIO.set('heartbeats',false);
//sockIO.set('heartbeat timeout', 1280);
sockIO.sockets.on('connection', function (socket) {
// new client is here!
console.log('YES SERVER IS RUNNING and __dirname is' + __dirname);
var APP = this;
对于包依赖
"dependencies": {
"exec": "^0.2.1",
"express": "^4.16.2",
"nodemailer": "^2.7.2",
"nodemailer-sendgrid-transport": "^0.2.0",
"sendgrid": "^4.10.0",
"socket.io": "^1.7.4"
}
解决方案
在这里回答 Socket.io 1.x:只使用 WebSockets?
基本上我禁用了来自客户端的轮询,只允许 websocket 作为传输。
推荐阅读
- oracle - 如何使用 XMLType 在 oracle db 中存储和检索 XML 请求
- c# - 在 C# 中使用 JsonConvert 反序列化具有泛型类型参数的类
- mongoose - 嵌套填充匹配函数使用父值的父值而不是父值
- javascript - 无法在 axios 成功响应拦截器中调度 redux 操作
- java - java-redis中的一个键是否存在具有不同对象的不同值的多重映射?
- android - 协程持有的泄漏服务
- dataframe - Rust polars: IntoSeries 特征没有为 &Series 实现
- powershell - Powershell XML 到 CSV
- directory - 如何通过ansible检查多个目录中的777权限
- android - 如何将未标记的 UI 元素扩展为对讲的图标?