socket.write(data[, encoding][, callback])


在套接字上发送数据。第二个参数用于在字符串情况下指定编码。默认使用 UTF8 编码。

【Sends data on the socket. The second parameter specifies the encoding in the case of a string. It defaults to UTF8 encoding.】

如果整个数据已成功刷新到内核缓冲区,则返回 true。如果所有或部分数据被排队在用户内存中,则返回 false。当缓冲区再次可用时,将发出 'drain'

【Returns true if the entire data was flushed successfully to the kernel buffer. Returns false if all or part of the data was queued in user memory. 'drain' will be emitted when the buffer is again free.】

可选的 callback 参数将在数据最终写出时执行,但可能不会立即执行。

【The optional callback parameter will be executed when the data is finally written out, which may not be immediately.】

有关更多信息,请参阅 Writablewrite() 方法。

【See Writable stream write() method for more information.】