Which is the better way to build real-time applications using Angular.js and Node.js?

后端 未结 5 1494
借酒劲吻你
借酒劲吻你 2020-12-29 13:36

I\'m beginner in Angular.js and Node.js, but I\'ve realized that there are two possible ways to make real-time applications. The first is using Socket.io and the other is us

相关标签:
5条回答
  • 2020-12-29 13:52

    It's better to use Socket.io in your case.

    Because you seem to do lots of interaction with the backend.If it's like that instead of querying the api in intervals just use Socket.io.

    Using socket will reduce the work on you both back end and client side and also will make it much more easier to control your event based stuff.

    0 讨论(0)
  • 2020-12-29 14:03

    Based on your use case, I think Socket.IO is the way to go. However, there are a few caveats to using WebSockets with Angular. I recommend you take a look at a blog post I wrote on the subject a while ago: http://briantford.com/blog/angular-socket-io.html

    0 讨论(0)
  • 2020-12-29 14:09

    We had to choose from an alternative between pusher (using Websocket) and Pubnub which uses Ajax for publish/subscribe real time events. Your Angular RESTful alternative is not enough when trying to do realtime communication across different users of the application. For example, you have a project management application used by a team. One team member might be adding/updating a task while another might be looking at the same time. The update needs to be published and all other user who are currently logged in will be subscribed for the changed event and can be notified.

    We've been using Pubnub and it works very fast although Pusher's technology is better but not supported by all browsers currently.

    I know the question is for AJ and NodeJS but i feel that using a third party subscription/publishing API makes it easier to manage because you'll not have to manage the nodejs server and the bigger load (when your app goes popular). Pusher/Pubnub is scalable and you can scale your app as far as you want.

    0 讨论(0)
  • 2020-12-29 14:12

    Socket.io has the following advantages:

    • less unnecessary trafic and rendering
    • lower latency
    • (arguably) cleaner code

    REST has these advantages:

    • Supported on all browsers and clients
    • Less open connections
    • Works better in clustered, proxied and otherwise complex network topologies

    Each of these points deserves a long discussion on it's own, some depend a lot on the application characteristics. But if you tag them by priority, you'll see what is probably best for you.

    0 讨论(0)
  • 2020-12-29 14:14

    If you want a fully real-time web application, then sockets are the way to go. Socket.io or SockJS are both extremely good clients. They have the ability to degrade gracefully when web sockets aren't supported, though, you may choose which transportation method you'd like to use.

    You'll have to build a data subscription service for changes to be propagated between all users. Tower.js and Meteor both use a reactive approach, and they use event listeners on model changes. Depending on how complex, or how powerful you want this feature, they'll be different implementations available.

    It does become increasingly more complex when trying to sync client-side and server-side data across many users connected at once. I'd suggest you take a look at those two frameworks, see how they work, and possibly replicate parts of it, or all of it's functionality.

    0 讨论(0)
提交回复
热议问题