我有我的网站,当我最近向下滚动时,有时会停滞或冻结,我在控制台中签到,每当我的网站停滞或冻结时,它在控制台中都会显示错误消息: WebSocket已经处于CLOSING或CLOSED状态
根据此question,我回滚到socket.io 2.0.3,现在没有出现错误消息,但有时仍然滞后。
网站:
<script src="../vendors/jquery/dist/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js"></script>
<script>
var URL_SERVER = 'https://www.mywebsite.com:3002';
var socket = io.connect(URL_SERVER);
socket.on('message', function(data) {
//stuff to do
});
</script>
服务器:
var fs = require('fs');
var https = require('https');
var express = require('express');
var app = express();
var options = {
key: fs.readFileSync('/the/key/path/mywebsite.com/privkey.pem'),
cert: fs.readFileSync('/the/cert/path/mywebsite.com/fullchain.pem')
};
var serverPort = 3002;
var server = https.createServer(options,app);
var io = require('socket.io')(server);
app.get('/',function(req,res){
res.sendFile(__dirname+'/index.html');
});
server.listen(serverPort, function(){
console.log('Server is working on...');
//console.log(__dirname);
});
io.on('connection', function(socket){
socket.emit("message","Welcome");
socket.on("newcot",function(data){
//stuff to do
});
//more stuff to do
});
我该如何解决?