Websockets和Firebase简介-如何构建实时应用



刚开始进行网络开发时,您不会经常考虑状态。因为HTTP是无状态协议。但是,有许多应用程序需要客户端和服务器之间存在持久的双向通信通道,以便它们可以不断地相互之间来回发送数据,并且服务器还可以一次将数据广播到所有连接的客户端。

输入Websockets。 Websocket是所有现代浏览器的本机功能,但是它们有点难以处理。它们的级别很低,每个浏览器以略有不同的方式实现它们。因此,如果您想构建一个实时应用程序,那么您将面临一些挑战。

幸运的是,通过使用一种称为Firebase的令人难以置信的服务,有一种非常简单的方法来开始使用Websocket。 Firebase是一家于2012年成立的初创公司,然后于2014年被Google收购。Firebase作为一项服务可以做很多事情,但是如果您需要了解一件事,那就是Firebase是最简单的方法构建一个实时应用,该应用在多个设备之间具有共享状态。 。

20 comments
  1. pls tell me that how to update OR send player vectors (movements) to my real time database in firebase asa i'm trying to make a simple multiplayer game using firebase RTDB and also how top get that movement value back to show other players in realtime? pls help there i no such tutorial for this IN UNITY 2D

  2. Sorry this is not a WebSocket connection, this is just Firebase's RealTimeDataBase.

    RealTimeDataBase itself is already a socket connection,

    but the RealTimeDataBase socket has its own rules.

    To really make a WebSocket connection with FireBase using your own rules, you have to follow this more or less, also using Firebase Functions, Hosting etc …

    take a look

    https://codereview.stackexchange.com/questions/193305/firebase-server-side-auth-with-persistent-websocket-connection?rq=1

  3. Great intro to what websockets are used for. Do you know of any resources that I could use to learn alternatives to Firebase? E.g. how to run websocket servers on instances of Google Compute Engine. My goal is to build a mobile app with an IM feature. If you don't know of any guides, would you please consider making one? I'd be more than happy to pay for it.

  4. started off promising with a great intorduction, but the example seemed to skip over a heap of details for people unfamiliar with server side javascript. was also hoping to see example code that i could run and experiment with so i could fill in the gaps.

  5. Hey buddy! Awesome video again. Keep em' coming. I have a question for you: I built an app using Firebase for the real-time connection stuff. I started considering moving to PouchDB or something like that, because I was worried that the free Firebase plan wouldn't hold up minimal traffic. How true is that?

  6. How do you subscribe to the deltas (changes) of a reference when it is updated? I don't want to reprocess a whole nested structure every time a leaf node is changed. Can probably be optimized with shouldcomponentupdate and immutable data structure if the delta is known. I can't find an elegant solution anywhere. Perhaps you have some ideas?

    Also firebase is probably only sending the deltas over the wire and not the entire object for every little change right?

  7. gerat episode as usual, and very educational. keep em coming. i don't understand how this channel didn't blow up yet

  8. Great intro to firebase and integration with React! Thanks for taking the time to teach these interesting topics, I really enjoy the quality of these videos!

Comments are closed.