chat-example
chat-example copied to clipboard
Failed to load resource
Hello there I'm working with:
Ubutu 14.04 Express 4.10.2 Socket.io 1.3.7
Vagrant Port fowarding :8001 to Box :80 Port fowarding :8002 to Box :3000
This is my App.js
var express = require('express'); var app = express(); var server = app.listen(3000);
var io = require('socket.io').listen(server); var http = require('http');
io.on('connection', function(socket){ console.log('a user connected'); socket.on('disconnect', function(){ console.log('user disconnected'); }); });
and this is my index.html
then when I open in the browser the index page I get:
Failed to load resource: the server responded with a status of 404 (Not Found) http://127.0.0.1:8001/socket.io/?EIO=3&transport=polling&t=1451934295598-10
any idea how to solve it?
var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.get('/', function(req,res) {
res.sendFile(__dirname + '/index.html');
});
io.on('connection', function(socket) {
console.log('a user connected')
socket.on('disconnect', function() {
console.log('a user disconnected');
});
});
http.listen(3000, function() {
console.log('Listening on port 3000');
});
Try this! Works for me.
var app = require('express')(); var http = require('http').Server(app);
app.get('/', function(req, res){ res.sendfile('index.html'); });
http.listen(3000, function(){ console.log('listening on *:3000'); }); We'll need an index.html file to serve, create a new file called index.html and enter the following in it:
nodemon app.js