Google Cloud Functions with socket.io

2020-03-27 01:33发布

问题:

My understanding is that to establish a persistent socket connection using socket.io the Node.js server should be always running. With Google Cloud Functions there isn't an always running Node.js server, so keeping a socket connection alive is not possible.

Is Cloud Run with a running Node.js server the best option to handle multiple socket connections using socket.io ?

回答1:

Neither Cloud Functions nor Cloud Run are able to support persistent socket connections for the same reasons. Each request has a timeout that can't be infinite. If you want to use socket.io effectively, you will need a different backend - one where you fully control the server instances.