Socket.io Failed to load resource

2019-08-30 18:08发布

问题:

i have error

 Failed to load resource http://localhost:3250/socket.io/1/?t=1376856906369

when i try do something with socket.io (loading work properly)

it is my first lines server

        var express = require('express')
      , http = require('http')
      , mysql = require('mysql');

    var app = express();
    var server = http.createServer(app);
    var io = require('socket.io').listen(server);


    server.listen(8080);

    app.set('view engine', 'swig');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + '/lib'));

回答1:

You are starting the server on port 8080, but you are trying to get socket.io from port 3250. So you either need to change this line:

//server.listen(8080);
server.listen(3250);

...or you use "http://localhost:8080" or just "http://localhost" in your browser.