Establishes a TCP connection to the specified port and host.
The port to connect to.
Optionalhost: stringThe host to connect to.
Optionaloptions: {Connection options.
OptionalallowHalfOpen?: booleanOptionalautoSelectFamily?: booleanOptionalautoSelectFamilyAttemptTimeout?: numberOptionalblockList?: BlockListOptionalfamily?: numberOptionalfd?: numberOptionalhints?: numberOptionalkeepAlive?: booleanOptionalkeepAliveInitialDelay?: numberOptionallocalAddress?: stringOptionallocalPort?: numberOptionallookup?: LookupFunctionOptionalnoDelay?: booleanOptionalonread?: OnReadOptsOptionalreadable?: booleanOptionalsignal?: AbortSignalOptionaltimeout?: numberOptionalwritable?: booleanA promise that resolves when the connection is successfully established.
Half-closes the TCP connection. It sends a FIN packet to the server, indicating that no more data will be sent. The server can still send data back until it also half-closes the connection.
Optionaloptions: { waitForClose?: boolean }Options for disconnecting. If waitForClose is true, the promise
will resolve only after the 'close' event is emitted.
A promise that resolves when the connection is half-closed or fully closed based on the provided options.
Writes data to the TCP socket.
The data to write. Can be a string or a Uint8Array.
Optionaloptions: { encoding?: BufferEncoding }Optional write options, such as encoding.
A promise that resolves when the data is successfully written.
StaticfromCreates a new TcpClient instance with the specified options.
Optionaloptions: SocketConstructorOptsOptions for creating the TCP connection. Defaults to connecting to port 80.
A new TcpClient instance.
A wrapper around
net.Socketthat provides Promise-based methods for connecting, ending, and writing data.This class simplifies the use of TCP sockets by converting the callback-based methods of
net.Socketinto Promise-based methods, making it easier to use with async/await syntax.Example usage: