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
I am new to socket.io and I tried to search but did not receive a response.
Websocket is interrupted when I refresh a page in Firefox. Therefore, the server side is waiting for client authorization.
Here is the code:
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) {
index.html
<script src="node_modules/socket.io-client/dist/socket.io.js"></script> <script> var socket = io.connect('http://localhost:8080'); socket.on('news', function (data) { alert(JSON.stringify(data)); console.log(data); socket.emit('my next event', { my: 'data' }); }); </script>
Amar Jan 03 '13 at 14:03 2013-01-03 14:03
source share