> For the complete documentation index, see [llms.txt](https://socket.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://socket.gitbook.io/docs/3-ke-hu-duan-apiclientapi/3.3-socket/socket_emit_eventname_args_ack.md).

# 3.3.7 socket.emit(eventName,\[...args]\[,ack])

* `eventName` (String)
* `args`
* `ack` (Function)
* **Return** `Socket`

向字符串名称标识的socket发出事件。可以包括任何其他参数。支持所有可序列化的数据结构，包括\`Buffer。

```javascript
socket.emit('hello','world');
socket.emit('with-binary',1,'2',{3:"4",5:new Buffer(6)});
```

`ack`参数是可选的，将通过服务器应答调用。

```javascript
socket.emit('ferret','tobi',data=>{
    console.log(data) // data 将是 'woot'
})

// 服务器：

// io.on('connection',socket=>{
//     socket.on('ferrec',(name,fn)=>{
//         fn('woot');
//     })
// })
```
