Reputation: 456
I'm trying to adapt a socket.io tutorial's example to my code, using the npm package socket.io-client
.
After this attempt I've obtained the error:
Failed to load resource: the server http://localhost:3000/socket.io/?EIO=3&transport=polling&t=1451092774034-0 responded with a status of 404 (Not Found)
Bellow the code:
exactly as prescribed by the package developer
var socket = require('socket.io-client')('http://localhost:3000');
socket.on('news', function(data) {
console.log(data);
socket.emit('my other event', {
my: 'data'
});
});
var express = require('express');
var app = express();
var server = require('http').Server(app);
var io = require('socket.io')(server);
app.use(express.static(__dirname+'/app'));
app.get('/', function(req,res){
res.sendFile('index.html');
});
io.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});
server.listen(process.env.PORT || 3000);
I suppose the problems is related with the line app.use(express.static(__dirname+'/app'))
. However, I don't know how to use this suspection to workaround the problem.
I appreciate any help.
Upvotes: 1
Views: 824
Reputation: 456
Problem solved. The related problem has to do with some conflicts with browsersync, as reported in this github's issue
Upvotes: 0