socket.io
socket.io copied to clipboard
Error during WebSocket handshake: Status line does not end with CRLF
Everytime socket try to connect i got an error : WebSocket connection to 'wss://playground-c9-doum.c9.io/socket.io/1/websocket/QBGO1ZlPhWUBkMVQ9cUP' failed: Error during WebSocket handshake: Status line does not end with CRLF socket.io.js:2371
On server side :
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);
});
});
client side :
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;
}
};