2014-09-13 91 views
4

我有這個錯誤請求。socket.io和node.js 400錯誤的請求

enter image description here

的紅色請求得到錯誤 - 400錯誤的請求,並採取更多的則30秒。經過錯誤的插座做工精細,但它花費更多的時間進行響應

在app.js代碼是如下

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); 
    }); 




    }); 

在客戶端代碼

<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> 

請幫助

+0

這裏是連接網址? – Ravi 2014-09-13 09:11:21

+0

對不起,我錯過了這個問題 – Sreejith 2014-09-15 05:18:25

回答

2

嘗試指定的完整URL爲

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

socket VAR

= io.connect('http://localhost:3000/') 
+4

爲什麼這會修復它? – 2015-03-07 12:04:33