# sails.sockets.emit( `socketIds`, [`event`], `data`)
### Purpose
Send a message to one or more sockets by ID.

### Overview
#### Parameters
|   |          Description        | Accepted Data Types | Required ? |
|---|-----------------------------|---------------------|------------|
| 1 |           IDs of sockets to receive message        | `string`, `array`            | Yes         |
| 2 |           Event name        | `string`            | No         |
| 3 |           Message data        | `object`            | Yes         |

### Example Usage
```javascript
// Controller action

sayHiToFriend: function(req, res) {
    var friendId = req.param('friendId');
    sails.sockets.emit(friendId, 'privateMessage', {from: req.session.userId, msg: 'Hi!'});
    res.json({
      message: 'Message sent!'
    });
}
```

### Notes
> + If the event name is not specified then the "message" event will be used by default. This would allow the target sockets to listen on the "message" event in order to react to the emit.



<docmeta name="uniqueID" value="sailssocketsemit963182">
<docmeta name="displayName" value="sails.sockets.emit()">


# sails.sockets.emit( `socketIds`, [`event`], `data`)
### Purpose
Send a message to one or more sockets by id.

### Overview
#### Parameters
|   |          Description        | Accepted Data Types | Required ? |
|---|-----------------------------|---------------------|------------|
| 1 |           IDs of sockets to receive message        | `string`, `array`            | Yes         |
| 2 |           Event name        | `string`            | No         |
| 3 |           Message data        | `object`            | Yes         |




### Example Usage
```javascript
// Controller action

sayHiToFriend: function(req, res) {
    var friendId = req.param('friendId');
    sails.sockets.emit(friendId, 'privateMessage', {from: req.session.userId, msg: 'Hi!'});
    res.json({
      message: 'Message sent!'
    });
}
```

### Notes
> + If the event name is not specified then the "message" event will be used by default. That means that target sockets listening for the `message` event in client-side code (e.g. `io.socket.on('message', function (data){ /* ... */ })`) will have that event handler triggered.
> + If _any_ of the target socket ids are unknown, an error is thrown (this error has a `code` property equal to `SAILS:HOOK:SOCKETS:NO_SUCH_SOCKET`).


<docmeta name="uniqueID" value="sailssocketsemit963182">
<docmeta name="displayName" value="sails.sockets.emit()">


Add note about what happens if target socket(s) do not exist.
Add note about what happens if target socket(s) do not exist.

see https://github.com/balderdashy/sails-hook-sockets/commit/604a5d7faaf96059409bb27302f875ed17500af1

Note that this code will not be accurate in default Sails installs until the next minor release when we can make the breaking change of updating the sails-hook-sockets dep.