socket.io - Socket.io 传输关闭和 ping 超时错误
问题描述
由于传输关闭或pingtimeout错误,套接字客户端正在断开连接。它是随机发生的。有时套接字客户端会稳定几个小时,然后开始随机断开连接。谁能帮我找到问题。
套接字客户端版本:2.1.0 套接字服务器版本:2.1.0,
客户代码
const socket = require('socket.io-client')
let url = 'http://localhost:5050'
let clientSocket = socket.connect(url, {
reconnection: true,
forceNew: true,
secure: true
})
clientSocket.on("connect", function (data) {
// console.log(clientSocket)
console.log("connection established");
});
clientSocket.on("event", function(data) {
console.log(data)
})
服务器代码
const socketio = require('socket.io');
this.io = socketio.listen(this.server,
{
'pingInterval': PING_INTERVAL,
'pingTimeout': PING_TIMEOUT
});
this.io.on('connection', function (socket) {
// const consumer = new ConsumerGroup(options, topic);
// reading data from add event and sending back the same data
console.log('Connected', socket.id);
const token = socket.handshake.query.token;
socket.on('disconnect', function () {
console.log(socket.id + ' -> Disconnected');
});
consumer.on('ready', function (message) {
console.log('Ready');
});
consumer.on('message', function (message) {
// sending message on socket when we recieve the message from kafka\
socket.emit('alarm', message);
});
consumer.on('error', function (err) {
console.log('error', err);
});
});
解决方案
推荐阅读
- spring-boot - Springboot抛出给杰克逊异常
- azure-functions - 发生错误发送事件:Azure 函数输出适配器未能将事件写入 Azure 函数作为流分析作业输出
- python - 用于获取数千条记录并将其附加到 falsk rest api 列表的高效 pymongo 查询
- ansible - 使用 ansible 在远程位置备份文件
- c# - 创建剪贴板数据以在 Access-Vbe 中使用
- hibernate - 如何在休眠中使用条件查询获取详细信息
- django - 使用 simplejwt 模块在 django 中修改 jwt 访问令牌到期时间
- php - 在 Woocommerce 3+ 中自定义一些结帐字段属性
- c# - 在 C# MVC 中执行的 OCTAVE .m 文件
- java - Primefaces 扩展 CK 编辑器始终呈现为 textarea