Skip to main content
Socket.prototype.write - net - Node documentation
method Socket.prototype.write

Usage in Deno

import { Socket } from "node:net";
Socket.prototype.write(
buffer: Uint8Array | string,
cb?: (err?: Error) => void,
): boolean

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

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.

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

See Writable stream write() method for more information.

Parameters

buffer: Uint8Array | string
optional
cb: (err?: Error) => void

Return Type

boolean
Socket.prototype.write(
str: Uint8Array | string,
encoding?: BufferEncoding,
cb?: (err?: Error) => void,
): boolean

Parameters

str: Uint8Array | string
optional
encoding: BufferEncoding
optional
cb: (err?: Error) => void

Return Type

boolean