Socket
The Socket class represents a TCP connection, from which you can
read and write data. A socket begins in a connected state (if the
socket fails to connect, an error is thrown). While in a connected
state, the socket’s ReadableStream and WritableStream can be
read from and written to respectively.
Properties
| Property | Modifier | Type |
|---|---|---|
closed | readonly | Promise<void> |
opened | readonly | Promise<SocketInfo> |
readable | readonly | ReadableStream<Uint8Array> |
writable | readonly | WritableStream<Uint8Array> |
Methods
close()
close(reason?): Promise<void>
Closes the socket and its underlying connection.
Parameters
| Parameter | Type |
|---|---|
reason? | any |
Returns
Promise<void>
startTls()
startTls(): Socket
Enables opportunistic TLS (otherwise known as StartTLS) which is a requirement for some protocols (primarily postgres/mysql and other DB protocols).