Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

socket.io and node.js 400 Bad Request

i've got this error requests.

enter image description here

The red coloured Request getting Error - 400 Bad request and it taking more then 30sec .After the error the socket work fine but it taking more time for response

In app.js the code is follows

 var app = express(),
      server = require('http').createServer(app); 
      //io = require('socket.io').listen(server);
      var sockets = require('socket.io')({
      'transports': ['websocket', 'flashsocket','htmlfile','xhr-polling','jsonp-polling']
      });
      var io = sockets.listen(server,{ resource: '/socket.io/','sync disconnect on unload':true });
io.sockets.on('connection', function(socket){
  socket.emit('server_emit');
  socket.on('search', function(cattype,pagNo,lang,film,iteamcat,starname){
    var query={'ProductType':cattype,'Language':lang,'ProductCategory':iteamcat,'UsedBy':starname,'UsedIn':film},
    field={},
    options={};

    db.collection("Product").find(query,field,options).toArray(function(error, Product2){     
      socket.emit('result',Product2);
    });




  });

In client side code

<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect();
        socket.on('server_emit', function(){
                console.log("Server emitted to Browser")
        });

</script>

Please help

like image 826
Sreejith Avatar asked Sep 13 '14 08:09

Sreejith


1 Answers

Try specifying the full URL as

<script src='http://localhost:3000/socket.io/socket.io.js'>

and in socket var

= io.connect('http://localhost:3000/')
like image 74
Ravi Avatar answered Oct 20 '22 00:10

Ravi