I am making a simple node.js application and intend to use socket.io, but so far I can not start the server.
This is my code:
var http = require('http'), io = require('socket.io'), fs = require('fs'); http.createServer(function(request, response){ fs.readFile(__dirname + '/index.html', function(err, data){ if(err){ response.writeHead(500, {'Content-Type': 'text/plain'}); return response.end('Error'); } response.writeHead(200, {'Content-Type': 'text/html'}); response.end(data); }); }).listen(1337); io.sockets.on('connection', function(socket){ socket.emit('pic', { addr: '/pic.jpg' }); socket.on('status', function(data){ console.log(data); }) })
and this is the result that I get:
[root@ip-10-224-55-226 node]
Socket.IO was installed by NPM and seems to be located in / root / node_modules / socket.io Because of this, I created sym-link (ln -s) of this directory in / srv / node, where is my server root.
dsljanus
source share