View our GitHub

Please visit sails-docs on GitHub to view documentation on your mobile device.

Edit Page

Gets the ID of a request socket object.;


Argument Type Details
1 socket A request socket (WebSocket/ object
e.g. req.socket.

Once acquired, the socket object's ID can be used to send direct messages to that socket (see sails.sockets.emit) or get information about the rooms that the socket is subscribed to (see sails.sockets.socketRooms).


// Controller action

getSocketID: function(req, res) {
  if (!req.isSocket) return res.badRequest();

  var socketId =;
  // => "BetX2G-2889Bg22xi-jy"

  return res.ok('My socket ID is: ' + socketId);


  • The phrase "request socket" here refers to an application-layer WebSocket/ connection. req.socket also exists for HTTP requests, but it refers to the underlying TCP socket at the transport layer, which is different. Be sure and ensure req.isSocket == true before using req.socket with this method.

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.


We wrote a book!

Get early access to the book
with promotion code: mcneildoc

Get the Book