Here is my server
var io = require('socket.io').listen(80);
io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});
Here is my client index.html
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('http://localhost:80');
socket.on('news', function (data) {
console.log(data);
socket.emit('my other event', { my: 'data' });
});
</script>
Here are my commaneds
node server.js
and on browser I am hitting URL localhost:80/index.html
after hitting above URL I am getting message Welcome to socket.io.
I am using nodeJS v0.10.9
socket.io
provides asocket.io
server, not a web server. Soindex.html
in the context ofsocket.io
doesn't exist.Instead, you could use Express to provide a basic web server, combined with
socket.io
to provide messaging: