简体   繁体   中英

socket.io and node.js 400 Bad Request

i've got this error requests.

在此输入图像描述

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

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/')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM