chat-example icon indicating copy to clipboard operation
chat-example copied to clipboard

Failed to load resource

Open josefrm opened this issue 9 years ago • 2 comments

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

Socket.IO chat

    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?

    josefrm avatar Jan 04 '16 19:01 josefrm

    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.

    anubhav7495 avatar Jan 22 '16 18:01 anubhav7495

    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:

    Hello world Hello world To test if this works, go to your terminal and run this app using

    nodemon app.js

    Seliniux777 avatar Mar 16 '18 02:03 Seliniux777