Is it a good idea to run Socket.io on a Firebase Cloud Function?

荒凉一梦 提交于 2020-12-29 19:05:08

问题


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:

  1. 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.
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!