Question: I have a clientid and username and i want them both send with the socket.

```
 client.userid = userid;
 client.username = username;
 client.emit('onconnected', { id: client.userid, name: client.username });

```

i tried this for example but it doesn't seem to work

Answer: 
You can try this

```
io.sockets.on('connection', function (socket) {
  socket.on('event_name', function(data) {
      // you can try one of these three options

      // this is used to send to all connecting sockets
      io.sockets.emit('eventToClient', { id: userid, name: username });
      // this is used to send to all connecting sockets except the sending one
      socket.broadcast.emit('eventToClient',{ id: userid, name: username });
      // this is used to the sending one
      socket.emit('eventToClient',{ id: userid, name: username });
  }
}

```

and on the client

```
 socket.on('eventToClient',function(data) {
    // do something with data
       var id = data.id
       var name = data.name // here, it should be data.name instead of data.username

 });

```
You should pass an object to socket event.

In server-side:

```
socket.emit('your-event', { name: 'Whatever', age: 18 })

```

In client-side:

```
socket.on('your-event', ({ name, age }) => {
    // name: Whatever
    // age: 18
})

```