Constructors

  • Creates a new ENet host for communicating with peers.

    Parameters

    • ipAddress: string
    • port: number

      The port number to bind to

    • peerLimit: number
    • channelLimit: number
    • usingNewPacket: boolean
    • usingNewPacketServer: boolean
    • OptionalincomingBandwidthLimit: null | number
    • OptionaloutgoingBandwidthLimit: null | number
    • OptionalenableCompressor: null | boolean
    • OptionalenableChecksum: null | boolean
    • Optionalseed: null | number

      Random number generator seed, or null for random seed

    Returns Host

Accessors

  • get channelLimit(): number

    Get the maximum allowed channels for future incoming connections.

    Returns number

    The channel limit

  • get ipAddress(): string

    Get the IP address of the host socket.

    Returns string

    The IP address as a string

  • get mtu(): number

    The maximum transmission unit (MTU), or the maximum packet size that will be sent by this host.

    Returns number

    The MTU value

  • get peerLimit(): number

    Get the maximum number of peers that can connect to this host.

    Returns number

    The peer limit

  • get port(): number

    Get the port number of the host socket.

    Returns number

    The port number

Methods

  • Queues a packet to be sent to all connected peers.

    Parameters

    • data: Buffer

      The packet data to broadcast

    • channelId: number

    Returns boolean

    True on success

  • Checks for any queued events on the host.

    Returns boolean

    True if there are queued events, false otherwise

  • Initiates a connection to a foreign host.

    Parameters

    • ipAddress: string
    • port: number

      The port number of the remote host

    Returns boolean

    True if connection initiated successfully, false otherwise

  • Sends any queued packets on the host to its designated peers.

    Returns boolean

    True on success

  • Get the host's current bandwidth limits.

    Returns object

    Object with optional 'incoming' and 'outgoing' properties (bytes/second), undefined if no limit

  • Get a snapshot of peer data by peer ID. Returns a NativePeer object containing current state and statistics.

    Parameters

    • netId: number

    Returns NativePeer

    NativePeer snapshot containing peer data

    Error if peer not found

  • Get the current time according to this host.

    Returns number

    Time in milliseconds since epoch

  • Get the number of connected peers.

    Returns number

    The count of currently connected peers

  • Send a reliable packet to a specific peer.

    Parameters

    • netId: number
    • data: Buffer

      The packet data to send

    • channelId: number

    Returns boolean

    True if packet queued successfully

    Error if peer not found or send fails

  • Checks for events on the host and shuttles packets between the host and its peers. Should be called regularly for adequate performance. Dispatches events to the emitter callback set via set_emitter().

    Returns void

    Error if emitter is not set

  • Adjusts the bandwidth limits of the host in bytes/second. ENet will strategically drop packets to ensure bandwidth is not overwhelmed. The bandwidth parameters also determine the window size which limits reliable packets in transit.

    Parameters

    • Optionalincoming: null | number

      Downstream bandwidth limit in bytes/second, or null for no limit (cannot be 0)

    • Optionaloutgoing: null | number

      Upstream bandwidth limit in bytes/second, or null for no limit (cannot be 0)

    Returns boolean

    True on success

    Error if limits are set to 0

  • Limits the maximum allowed channels of future incoming connections.

    Parameters

    • channelLimit: number

    Returns boolean

    True on success

    Error if channel_limit is 0

  • Set the event emitter callback function. This callback will be invoked during service() calls when events occur.

    Parameters

    • emitter: (...args: any[]) => any

      The callback function to handle events (connect, raw, disconnect)

    Returns void

  • Set the maximum transmission unit (MTU) for this host.

    Parameters

    • mtu: number

      The MTU value (must be between PROTOCOL_MINIMUM_MTU and PROTOCOL_MAXIMUM_MTU)

    Returns boolean

    True on success

    Error if MTU is out of valid range