Sockets vs. Ajax in Sails

87 views
Skip to first unread message

James Dixon

unread,
Feb 26, 2015, 11:05:19 PM2/26/15
to sai...@googlegroups.com
Hi all, very new to Sails, Sockets and this board, so excuse me if my question has been answered elsewhere (I did search). With Sails being socket.io-enabled, when would I use sockets over something like Ajax? For example, I'm currently building an application that uses React.js for the front-end and Sails for everything else. Normally, in a single page application, if I wanted to authenticate against an endpoint, I would use Ajax to do so. Can I effectively use something like io.socket.post(url, [data], [cb]) in Sails to accomplish the same thing? Are there pros/cons to each approach?

Thanks in advance,
James

Izzet Pembeci

unread,
Feb 27, 2015, 4:02:44 PM2/27/15
to sai...@googlegroups.com
Socket.io helps you to push some data to the client without client initiating the process as in Ajax. The typical app is chat. If some message comes from client A to the server, then server can relay this message to other clients through their registered sockets. You eliminate the need of clients to poll the server for a possible new message periodically. They can just sit there and wait for the server to notify them. So for your example Ajax will suffice and will be actually easier. Since if you do this via socket you need to add code to the server for listening such requests and reply accordingly. I am new to Sails and telling all of these regardless of Sails. May be Sails is using sockets in a more creative way invalidating my answer.

iZzeT
Reply all
Reply to author
Forward
0 new messages