I\'m 100% new to Socket.IO and have just installed it. I was trying to follow some examples, and can get the server side running but I can\'t seem to get the client side con
In same origin policy, localhost:8090
and localhost
are not the same origin (different port), so localhost/index.html
cannot connect to socket.io on localhost:8090.
One option is to make index.html on localhost:8090
(see code below). Then you just put "index.html" into the same directory of your server script, start the server and type localhost:8090
in your browser.
var fs = require('fs');
server = http.createServer(function(req, res){
fs.readFile(__dirname + '/index.html', 'utf-8', function(err, data) { // read index.html in local file system
if (err) {
res.writeHead(404, {'Content-Type': 'text/html'});
res.end('Page Not Found
');
} else {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(data);
}
});
});