This question has been asked previously but haven't found any solution in prior replies.
Socket.IO gives me two problems:
- server side gave this error - ERROR - listen EACESS I read stackoverflow and resolved this with issuing a sudo command to start the server.
now clientside doesnt seem to find the socket.io.js file as per the script line -
I understand file is not found by using the chrome developer tools console which has a 404 error on the file.
I read that this file is created on the fly by server. But I did a 'ls-a' on the root folder. Couldn't find the socket.io/socket.io.js file.
Any ideas?
For reference here is my server code -
var http = require('http'),
path = require("path"),
url = require("url"),
fs = require("fs"),
mime = require("mime"),
io = require("socket.io").listen(server);
var homepath = ".";
var server = http.createServer(function (req, res) {
var uri = url.parse(req.url).pathname;
var filepath = path.join(homepath, uri);
console.log(filepath);
path.exists(filepath, function (exists) {
if (!exists) {
//404 response
res.writeHead(404, {
"Content-Type": "text/plain"
});
res.write("404 File not Found \n");
res.end();
} else {
if (fs.statSync(filepath).isDirectory()) {
filepath += '/index.html';
filepath = path.normalize(filepath);
}
fs.readFile(filepath, "binary", function (err, data) {
if (err) {
res.writeHead(500, {
'Content-Type': 'text/plain'
});
res.write('500 File read error \n');
res.end();
} else {
var contentType = mime.lookup(filepath);
res.writeHead(200, {
'Content-Type': contentType
});
res.write(data, 'binary');
res.end();
}
});
}
});
//sockets part starts here
io.sockets.on('connection', function (socket) {
socket.on('test', function (data) {
console.log('i got something');
console.log(data.print);
});
});
});
server.listen(3000);
server.on('error', function (e) {
console.log(e);
});
console.log('Server listening on Port 3000');