mardi 24 février 2015

SocketIO connection refused

I am trying to get socket IO to work, but I keep getting connection refused. I guess connection refused is better than connection timeout, as refused mean's something is stopping it somewhere?


Anyway the code is from socketIO's tutorial website:


Client side, located in /home/server/nodejs/expressocket.js:



var app = require('http').createServer(handler)
var io = require('socket.io')(app);
var fs = require('fs');

app.listen(8000);

function handler (req, res) {
fs.readFile(__dirname + '../public_html/socketio.htm',
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading index.html');
}

res.writeHead(200);
res.end(data);
});
}

io.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});


And then server side located in /home/server/public_html/socketio.js



<!DOCTYPE html>
<head>
<script src="http://ift.tt/1Abvuox"></script>
</head>
<body>
<h1>Socket IO Test</h1>
<script>
var socket = io('http://localhost:8000');
socket.on('news', function (data) {
console.log(data);
socket.emit('my other event', { my: 'data' });
});
</script>
</body>
</html>


I've got the right port in there, and the server should be listening on that port. But why is it getting refused?


Aucun commentaire:

Enregistrer un commentaire