每次socket.io尝试连接我都有错误(chrome 33 / firefox 24):
与'wss://playground-c9-doum.c9.io/socket.io/1/websocket/QBGO1ZlPhWUBkMVQ9cUP'的WebSocket连接失败:WebSocket握手期间出错:状态行不以CRLF socket.io.js结束:2371
在服务器端:
var io = socket.listen(server);
var store = require('connect-mongo')(express);
io.set('authorization', passportSocketIo.authorize({
passport: require('passport'),
cookieParser: express.cookieParser,
key: 'connect.sid', // the name of the cookie where express/connect stores its session_id
secret: constant.SALT, // the session_secret to parse the cookie
store: new store({
mongoose_connection: db,
collection: constant.SESSION_COLLECTION,
}),
success: onAuthorizeSuccess, // *optional* callback on success - read more below
fail: onAuthorizeFail,
}));
io.sockets.on('connection', function (socket) {
socket.on('chat:newText', function (data) {
console.log(socket.handshake.user);
data.username = socket.handshake.user.username;
io.sockets.emit('chat:newText', data);
});
});
客户方:
var connect = function () {
if (Auth.isLoggedIn() === true) {
socket = io.connect();
connected = true;
return true;
}
else {
console.log('Socket wont connect as user is not logged in');
return false;
}
};
我正在使用快递,护照,passport-socket.io ......
我不认为问题来自passport-socket.io,因为我尝试删除套接字配置的'auth'部分(io.set('authorization')),但我遇到了同样的问题。
我还试图给客户端socket.connect(url)一个特定的url,但也没有工作。
Socket.io没有完全失败,websocket连接是abord所以它开始xhr-polling(痛苦......)。
完成了很多研究并没有找到任何关于该问题的内容(也在github上发布了一个新问题)。
npm socket.io -v给出1.3.8 /socket.io/socket.io.js(client)是Socket.IO.js build:0.9.16