-3

How does Socket.io really work? I downloaded a simple node chat app to check it out, and under google chrome's network tab I inspected the HTTP requests. For a proper update of the chat, one can only assume that my javascript on client-side will keep sending constantly http requests checking out if there are any updates chat, but it doesn't show any requests sent and yet still - when I send a message on a different tab i can see an update on my tab.

https://github.com/lcristianiim/chat-app

I'd also love to know the basics of sockets.io, such as what happens once a user disconnects? Thanks!

user1938653
  • 611
  • 1
  • 9
  • 21
  • Title looks the same but the questions are different. I looked over what you sent and they discuss events, which I asked about too but on top I wanted to understand how the update system work, which is not included in the link you sent. – user1938653 Jul 28 '16 at 18:50
  • The questions really are pretty much the same. You should really read the comments there, the answer to everything you're asking is available on that question's page. – Patrick Roberts Jul 28 '16 at 18:58

1 Answers1

-1

It uses WebSockets as the underlying primary technology. You can optionally disable WebSockets as its default transport if you'd like to see those spammy long-polling requests in your developer console.

Patrick Roberts
  • 49,224
  • 10
  • 102
  • 153
  • Oh, so they just use a way to cover the "spamming"? where in reality, there is actually non-stop http requests sent asking for updates? – user1938653 Jul 28 '16 at 18:52
  • @user1938653 no. WebSockets are inherently different because they offer an alternative to normal HTTP requests which close at the end of sent data. On the contrary, WebSockets keep an open live connection on a single HTTP request where both the client and the server can send data over the connection at any time. It's much more efficient than the older technique of long-polling before websockets came along. – Patrick Roberts Jul 28 '16 at 18:54
  • What I meant when I said you can disable a transport, is that socket.io uses multiple fallback technologies in the case that a particular browser using the library does not support a more modern, efficient technology like websockets or flashsockets. That's why it's so popular because it abstracts several different layers away into a simple API. – Patrick Roberts Jul 28 '16 at 18:57
  • Thanks for your help, thumbs up for it. Btw; does the client side only awaits(pending) for further responses, which could be just about anything? (Objects, arrays, whatever). – user1938653 Jul 28 '16 at 19:22
  • @user1938653 socket.io can send anything that's serializable. And both the client _and server_ "await" data from each other through the socket connection. – Patrick Roberts Jul 28 '16 at 19:40
  • and they both communicate through a security key(which can be found on socket.id) in order to identify each other's right socket {} object on node? – user1938653 Jul 28 '16 at 19:48
  • @user1938653 it's not a "security" key, it's just a unique reference... – Patrick Roberts Jul 28 '16 at 20:02
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/118577/discussion-between-user1938653-and-patrick-roberts). – user1938653 Jul 28 '16 at 20:04