# 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');
//     })
// })
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://socket.gitbook.io/docs/3-ke-hu-duan-apiclientapi/3.3-socket/socket_emit_eventname_args_ack.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
