Logo Questions Linux Laravel Mysql Ubuntu Git Menu

AngularJS and Websockets

I'm trying to learn the HTML5/Node.js/Express/MongoDB/AngularJS/Websocket thing that seems to have everyone excited right now.

As a slight backfire, I'm actually having difficulty drawing lines on what each technology actually does (especially with ejs as a template engine). Javascript and HTML everywhere!

Particularly, I'm having trouble separating the services provided by websockets (or something like socket.io), and AngularJS. They both seem to try to offer dynamism without having to resend an entire HTML page.

Are they substitutes for one another? Or do they serve different purposes?

Also, both these technologies seem to move towards single-page web applications that bypass Express' routing. What then, is leveraged by Express when using Websockets/AngularJS? It seems like the traditional routing offered by Express is substituted for just altering the view in a single-page in AngularJS

like image 712
gone Avatar asked Mar 23 '23 02:03


1 Answers

AngularJS is a javascript library which does lots and lots of different things. The one of those many things which is closest related to WebSockets is the layer on top of the vanilla Javascript feature XmlHttpRequest.

Both XmlHttpRequest and WebSockets are techniques for exchanging data with a server without having to reload the website. The difference is that XmlHttpRequest (often referred to as AJAX) follows a request-response model (the client makes a request, the server answers), while WebSockets use a bidirectional channel where both the client and the server can send messages at any time.

like image 71
Philipp Avatar answered Apr 01 '23 20:04