Skip to content

TCP Server Connection

The TCP Server Connection class represents an active connection to a TCP server.

import TCPConnection from "embedded:io/tcp-server-connection";

Creates a new TCP server connection instance.

TCPConnection(server, from)

server - The parent TCP server instance.

from - The client address information.

Closes the TCP connection.

close()

Reads data from the TCP connection.

read(count)

count - The number of bytes to read.

A Buffer containing the read data.

Writes data to the TCP connection.

write(data, options)

data - The data to write.

options (optional) - Write options.

A method that is called when an error occurs on the connection.

tcpError(error)

error - An Error object describing the error.

A method that is called when data is available to read.

tcpReadable(count)

count - The number of bytes available to read.

A method that is called when the connection is ready for writing.

tcpWritable(count)

count - The number of bytes that can be written.

TCP Server Connection Class Pattern