Sails exposes several methods (
sails.sockets.*) which provide a simple interface for realtime communication with connected socket clients. This is useful for pushing events and data to connected clients in realtime, rather than waiting for them to actively request it using HTTP. This is true regardless of whether a client sockets was connected from a browser tab, from an iOS app, or even from your favorite household IoT appliance.
These methods are implemented using a built-in instance of Socket.io, which is available directly as
sails.io (see below). However, in almost every case, you should call the
sails.sockets.* methods (either directly, or via a higher level abstraction such as resourceful pubsub methods).
The API exposed by the
sails.sockets.* methods is flexible enough out of the box to cover the requirements of most applications, and using them will future-proof your app against possible changes in the underlying implementation. However, if you are working on bringing some legacy code from a vanilla Socket.io app into your Sails app, it can be useful to talk to Socket.io directly. To accomplish this, Sails provides raw access to the underlying socket.io singleton (
sails.io. See the Socket.io docs for more information, and if you go this route, please proceed with care.
Is something missing?
If you notice something we've missed or could be improved on, please follow this link and submit a pull request to the sails-docs repo. Once we merge it, the changes will be reflected on the website the next time it is deployed.
- Blueprint API
- Command Line Interface
- Response (`res`)
- Waterline (ORM)
- Resourceful PubSub
- Socket Client
We wrote a book!
Get early access to the book
with promotion code: mcneildoc