sahil sahil - 1 month ago 71
Node.js Question

socket.io GET /socket.io/?EIO=3&transport=polling&t=LV9VGzC" Error (404): "Not found"

//backend code
var express = require("express");
var app = express();
var http = require('http');

var startServer=http.createServer(app);
var socketIO = require('socket.io').listen(startServer);
startServer.listen(8080, function () {
console.log('server running on',8080)
});

socketIO.on('connection', function (socket) {
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>connected')
var userSocketObject = {};
userSocketObject.socket_id = socket.id;
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});

//index.html code angularjs
var socket = io.connect('http://127.0.0.1:8080');
socket.on('news', function(data){
console.log(data);
socket.emit('my other event', {my: 'data'});
});


I'm trying to connect but I'm getting an error in the browser:

GET http://127.0.0.1:8080/socket.io/?EIO=3&transport=polling&t=LV9VGzC" Error (404): "Not found"

Answer

i have resolved the problem , the problem was in directory path app.use(express.static(path.join('public')))