Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js Cannot GET /socket.io

I have the following app with express/socket.io (the app is listening and live without any errors). When I http-request it I get the following error:

GET http://xxxxxxx.com:3035/socket.io/1/?t=1449090610579 400 (Bad Request)

And on the socket.io reponse at http://xxxxxxx.com:3035/socket.io I get:

Cannot GET /socket.io

app.js:

var express = require('express'),
    http = require('http'),
    sio= require('socket.io'),
    fs=require('fs'),
    app = express();

var mysql      = require('mysql');
var connection = mysql.createConnection({
        host: 'localhost',
        user: 'xxxxxxx',
        password: 'xxxxxxx',
        database: 'xxxxxxxxx'
    }
);
connection.connect();

// Start the server
var server=app.listen(3035, function () {
    console.log("Express server listening on port %d",3035);
});
app.io=io=sio.listen(server);
.
.
.

on the client side:

var socket = io.connect('http://xxxxxx.com:3035');
like image 950
mediaroot Avatar asked May 12 '26 10:05

mediaroot


1 Answers

Your sio is a function. You need to call it with your server as an argument.

Add server=require('http').Server(app) sio=require('socket.io')(server)

like image 175
Phil Dornfeld Avatar answered May 14 '26 23:05

Phil Dornfeld