Error: The connection to <websocket> was interrupted while the page was loading.
Source File: localhost/socket.io/node_modules/socket.io-client/dist/socket.io.js
Line: 2371
Run Code Online (Sandbox Code Playgroud)
我是socket.io的新手,我试图搜索这个,但我没有得到答案.
当我在Firefox上刷新页面时,Websocket被中断.这就是服务器端等待授权客户端的原因.
这是代码:
server.js-->
var app = require('http').createServer(handler)
, io = require('socket.io').listen(app)
, fs = require('fs')
app.listen(8080);
function handler (req, res) {
fs.readFile(__dirname + '/index.html',
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading index.html');
}
res.writeHead(200);
res.end(data);
});
}
io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
//alert(JSON.stringify(data));
console.log(data);
});
});
Run Code Online (Sandbox Code Playgroud)
的index.html
<script …Run Code Online (Sandbox Code Playgroud)