我收到了此错误请求。
红色请求获取错误 - 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 :(得分:2)
尝试将完整网址指定为
<script src='http://localhost:3000/socket.io/socket.io.js'>
并在socket
var
= io.connect('http://localhost:3000/')