Getting socket.io, express & node-http2 to communicate though HTTP/2 Getting socket.io, express & node-http2 to communicate though HTTP/2 express express

Getting socket.io, express & node-http2 to communicate though HTTP/2


A little bit late but with Express4 and Spdy (npm) is working great.

bin/www:

var app = require('../app');var debug = require('debug')('gg:server');var spdy = require('spdy');var fs = require('fs');var port = normalizePort(process.env.PORT || '3000');app.set('port', port);var options = {    key: fs.readFileSync(__dirname + '/server.key'),    cert: fs.readFileSync(__dirname + '/server.crt')}var server = spdy.createServer(options, app);var io = app.ioio.attach(server);server.listen(port);server.on('error', onError);server.on('listening', onListening);...

app.js:

...var app = express();var io = app.io = require('socket.io')();...

client screenshot:enter image description here


As discussed in comments Chrome has recently stopped allowing the older NPN negotiation for HTTP/2 and insists on the newer ALPN protocol instead. See this article for more info: https://ma.ttias.be/day-google-chrome-disables-http2-nearly-everyone-may-31st-2016/

So you basically need Node.js to support ALPN which it looks as has only been added in v5 so far: https://github.com/nodejs/node/pull/2564 . An alternative would be to route your NodeJs calls through a webserver which is easier to upgrade OpenSSL (e.g. Nginx or Apache) to support HTTP/2 over ALPN.

You confirmed this was the issue by using the testssl.sh program which confirmed no ALPN support and the fact Firefox uses HTTP/2.