-
Notifications
You must be signed in to change notification settings - Fork 2
TCPClient
TCP client socket implementation.
-
Client↳
TCPClient
• new TCPClient(clientOptions, socket?)
| Name | Type |
|---|---|
clientOptions |
ClientOptions |
socket? |
Socket |
Client.constructor
• Optional clientOptions: ClientOptions
Client.clientOptions
• eventHandlers: Object
▪ [key: string]: [Function[], (Buffer | undefined)[]]
Client.eventHandlers
• isClosed: boolean
Client.isClosed
• Optional socket: Socket
▸ close(): void
Close socket.
void
Client.close
▸ connect(): void
Connect to server.
void
Client.connect
▸ Private error(error): void
| Name | Type |
|---|---|
error |
Error |
void
▸ getLocalAddress(): undefined | string
undefined | string
local IP address
Client.getLocalAddress
▸ getLocalPort(): undefined | number
undefined | number
local port
Client.getLocalPort
▸ getRemoteAddress(): undefined | string
undefined | string
remote IP address
Client.getRemoteAddress
▸ getRemotePort(): undefined | number
undefined | number
remote port
Client.getRemotePort
▸ offClose(fn): void
Unhook handler for close event.
| Name | Type | Description |
|---|---|---|
fn |
Function |
remove close callback. |
void
Client.offClose
▸ offConnect(fn): void
Unhook handler for connection event.
| Name | Type | Description |
|---|---|---|
fn |
Function |
remove connect callback. |
void
Client.offConnect
▸ offData(fn): void
Unhook handler for incoming data.
| Name | Type | Description |
|---|---|---|
fn |
Function |
remove data callback. |
void
Client.offData
▸ offError(fn): void
Unhook handler for socket errors.
| Name | Type | Description |
|---|---|---|
fn |
Function |
remove existing error callback |
void
Client.offError
▸ onClose(fn): void
User hook for close event.
| Name | Type | Description |
|---|---|---|
fn |
Function |
on close callback. |
void
Client.onClose
▸ onConnect(fn): void
User hook for connection event.
| Name | Type | Description |
|---|---|---|
fn |
Function |
on connect callback. |
void
Client.onConnect
▸ onData(fn): void
User hook for incoming data.
| Name | Type | Description |
|---|---|---|
fn |
Function |
on data callback. Function is passed a Buffer object. |
void
Client.onData
▸ onError(fn): void
User hook for socket errors.
| Name | Type | Description |
|---|---|---|
fn |
Function |
on error callback. Function is passed a Buffer object with the error message |
void
Client.onError
▸ send(data): void
Send buffer on socket.
throws An error will be thrown when buffer data type is incompatible.
| Name | Type | Description |
|---|---|---|
data |
Buffer |
to be sent |
void
Client.send
▸ sendString(data): void
Send string on socket.
| Name | Type |
|---|---|
data |
string |
void
Client.sendString
▸ Protected socketClose(): void
Defines the steps to be performed during close.
void
Client.socketClose
▸ Protected socketClosed(hadError): void
Base close event procedure responsible for triggering the close event.
| Name | Type |
|---|---|
hadError |
boolean |
void
Client.socketClosed
▸ Protected socketConnect(): void
Specifies how the socket gets initialized and created, then establishes a connection.
void
Client.socketConnect
▸ Protected socketConnected(): void
Base connect event procedure responsible for triggering the connect event.
void
Client.socketConnected
▸ Protected socketData(data): void
Base data event procedure responsible for triggering the data event.
| Name | Type | Description |
|---|---|---|
data |
Buffer |
data buffer. |
void
Client.socketData
▸ Protected socketError(message): void
Base error event procedure responsible for triggering the error event.
| Name | Type |
|---|---|
message |
Buffer |
void
Client.socketError
▸ Protected socketHook(): void
Specifies hooks to be called as part of the connect procedure.
void
Client.socketHook
▸ Protected socketSend(buffer): void
Defines how data gets written to the socket.
| Name | Type | Description |
|---|---|---|
buffer |
Buffer |
data to be sent |
void
Client.socketSend