问题
Implementing it works, but I have read that due to how Cloud Functions are designed they are not the best way to use socket.io. Why?
回答1:
Actually, socket.io does not work with Cloud Functions. Cloud Functions have the following properties that make them incompatible with long-lived socket connections:
- The maximum duration of a Cloud Function can only be 9 minutes. The socket will be forced closed after that time. This is counter to the normal expectation of socket.io to keep a socket connection alive indefinitely.
- Cloud Functions will read the entire contents of the request, and only then will write the entire contents of the response. There is only one full round trip - a client can not "chat back and forth" over the connection with the function.
See also
- Google Cloud Functions with socket.io
- Run a web socket on Cloud Functions for Firebase?
- Is it possible to host a express and socket.io app on Firebase Hosting?
来源:https://stackoverflow.com/questions/56903043/is-it-a-good-idea-to-run-socket-io-on-a-firebase-cloud-function