Options
All
  • Public
  • Public/Protected
  • All
Menu

Class SocketClientTCP

Represents a TCP Client connection.

Hierarchy

Index

Constructors

constructor

  • new SocketClientTCP(portTo: number, hostTo: string, ipVersion?: "IPv4" | "IPv6"): SocketClientTCP
  • Creates, and then attempts to connect to a remote server given an address. If no connection can be made, an Error is thrown.

    Parameters

    • portTo: number

      The host of the address to connect this TCP client to.

    • hostTo: string

      The host of the address to connect this TCP client to.

    • Optional ipVersion: "IPv4" | "IPv6"

      An optional specific IP version to use. Defaults to IPv4.

    Returns SocketClientTCP

Properties

Readonly hostTo

hostTo: string

The target host of the socket.

isBlocking

isBlocking: boolean

Gets/sets the blocking nature of the Socket. True if to block, false otherwise.

When a socket is blocking, calls such as receive() and accept() will synchronously wait until there is data to return from those calls. When a socket is not set to block, they will check and immediately return undefined when there is no data from those calls.

Readonly isDestroyed

isDestroyed: boolean

Flag if this socket has been manually disconnected and thus destroyed. Destroyed sockets cannot be re-used. True if this socket has been destroyed and disconnected. False otherwise.

NOTE: On unexpected socket errors this may not be set correctly. This check can only ensure this socket disconnected in an expected fashion.

Readonly isIPv4

isIPv4: boolean

Flag if the socket is Internet Protocol Version 4 (IPv4).

Readonly isIPv6

isIPv6: boolean

Flag if the socket is Internet Protocol Version 6 (IPv6).

Readonly portFrom

portFrom: number

The local port the socket is bound to.

Readonly portTo

portTo: number

The port this socket is connected/sends to.

Methods

disconnect

  • disconnect(): void
  • Disconnects this so. Once this is called the socket is considered "destroyed" and no no longer be used for any form of communication.

    Returns void

receive

  • receive(): Buffer | undefined
  • Attempts to Receive data from the server and return it as a Buffer.

    Returns Buffer | undefined

    A Buffer instance with the data read from the connected server. If set to blocking this call will synchronously block until some data is received. Otherwise if there is no data to receive, this will return undefined immediately and not block.

send

  • send(data: string | Buffer | Uint8Array): void
  • Sends the data to the connected server.

    Parameters

    • data: string | Buffer | Uint8Array

      The data you want to send, as a string, Buffer, or Uint8Array.

    Returns void

Generated using TypeDoc