Class NativePeer

A snapshot of peer data and statistics. This struct contains a point-in-time copy of peer information. To perform operations on the peer, use the methods which require a Host reference.

Constructors

Accessors

  • get channelCount(): number

    Number of channels allocated for communication with this peer.

    Returns number

  • get connected(): boolean

    Whether this peer is currently in a connected state.

    Returns boolean

  • get incomingBandwidth(): number

    Downstream bandwidth of the peer in bytes/second.

    Returns number

  • get incomingBandwidthThrottleEpoch(): number

    Incoming bandwidth throttle epoch.

    Returns number

  • get incomingDataTotal(): number

    Total amount of downstream data received from this peer.

    Returns number

  • get ip(): string

    The IP address of the peer.

    Returns string

  • get lastRoundTripTime(): number

    Last round trip time.

    Returns number

  • get lastRoundTripTimeVariance(): number

    Last round trip time variance.

    Returns number

  • get lowestRoundTripTime(): number

    Lowest round trip time recorded.

    Returns number

  • get mtu(): number

    The maximum transmission unit (MTU) for this peer.

    Returns number

  • get netId(): number

    The peer's network ID.

    Returns number

  • get outgoingBandwidth(): number

    Upstream bandwidth of the peer in bytes/second.

    Returns number

  • get outgoingBandwidthThrottleEpoch(): number

    Outgoing bandwidth throttle epoch.

    Returns number

  • get outgoingDataTotal(): number

    Total amount of upstream data sent to this peer.

    Returns number

  • get packetLoss(): number

    Mean packet loss of reliable packets as a ratio.

    Returns number

  • get packetLossVariance(): number

    Variance of the mean packet loss.

    Returns number

  • get packetsLost(): number

    Total number of packets lost from this peer.

    Returns number

  • get packetsSent(): number

    Total number of packets sent to this peer.

    Returns number

  • get packetThrottle(): number

    Current packet throttle value.

    Returns number

  • get packetThrottleAcceleration(): number

    Packet throttle acceleration rate.

    Returns number

  • get packetThrottleDeceleration(): number

    Packet throttle deceleration rate.

    Returns number

  • get packetThrottleInterval(): number

    Packet throttle interval.

    Returns number

  • get pingInterval(): number

    Ping interval in milliseconds.

    Returns number

  • get port(): number

    The port number of the peer.

    Returns number

  • get roundTripTime(): number

    Mean round trip time (RTT) in milliseconds between sending a reliable packet and receiving its acknowledgement.

    Returns number

  • get roundTripTimeVariance(): number

    Round trip time (RTT) variance in milliseconds.

    Returns number

  • get rtt(): number

    Round trip time (RTT) in milliseconds.

    Returns number

  • get state(): number

    The peer's current state (as numeric value).

    Returns number

  • get timeoutLimit(): number

    Timeout limit value.

    Returns number

  • get timeoutMaximum(): number

    Maximum timeout value in milliseconds.

    Returns number

  • get timeoutMinimum(): number

    Minimum timeout value in milliseconds.

    Returns number

Methods

  • Request a disconnection from this peer. An Event::Disconnect will be generated once the disconnection is complete.

    Parameters

    • host: Host

      The host instance managing this peer

    • data: number

      An integer value to pass to the peer upon disconnection

    Returns boolean

    True on success

  • Request a disconnection from this peer, but only after all queued outgoing packets are sent. An Event::Disconnect will be generated once the disconnection is complete.

    Parameters

    • host: Host

      The host instance managing this peer

    • data: number

      An integer value to pass to the peer upon disconnection

    Returns boolean

    True on success

  • Force an immediate disconnection from this peer. No Event::Disconnect will be generated. The foreign peer is not guaranteed to receive the disconnect notification.

    Parameters

    • host: Host

      The host instance managing this peer

    • data: number

      An integer value to pass to the peer upon disconnection

    Returns boolean

    True on success

  • Send a ping request to this peer. Ping requests factor into the mean round trip time. ENet automatically pings all connected peers at regular intervals, however this function may be called to ensure more frequent ping requests.

    Parameters

    • host: Host

      The host instance managing this peer

    Returns void

  • Forcefully disconnect this peer without notification. The foreign host represented by this peer is not notified of the disconnection and will timeout.

    Parameters

    • host: Host

      The host instance managing this peer

    Returns boolean

    True on success

  • Send a reliable packet to this peer on the specified channel.

    Parameters

    • host: Host

      The host instance managing this peer

    • channelId: number
    • data: Buffer

      The packet data to send

    Returns boolean

    True if packet queued successfully

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

    Parameters

    • host: Host

      The host instance managing this peer

    • 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

  • Set the interval at which pings will be sent to this peer in milliseconds. Pings are used to monitor connection liveness and dynamically adjust the throttle during periods of low traffic for better responsiveness during traffic spikes.

    Parameters

    • host: Host

      The host instance managing this peer

    • pingInterval: number

    Returns boolean

    True on success

  • Configure throttle parameters for this peer. The throttle represents a probability that an unreliable packet should be sent. When throttle is at maximum, 100% of unreliable packets are sent. When at 0, all unreliable packets are dropped.

    Parameters

    • host: Host

      The host instance managing this peer

    • interval: number

      Interval in milliseconds over which to measure lowest mean RTT

    • acceleration: number

      Rate at which to increase throttle probability as RTT declines

    • deceleration: number

      Rate at which to decrease throttle probability as RTT increases

    Returns boolean

    True on success

  • Set timeout parameters for this peer. Timeout values use an exponential backoff mechanism. If a reliable packet is not acknowledged within some multiple of the average RTT, the timeout will be doubled until it reaches the limit.

    Parameters

    • host: Host

      The host instance managing this peer

    • limit: number

      The timeout limit (defaults to PEER_TIMEOUT_LIMIT if 0)

    • minimum: number

      The minimum timeout (defaults to PEER_TIMEOUT_MINIMUM if 0)

    • maximum: number

      The maximum timeout (defaults to PEER_TIMEOUT_MAXIMUM if 0)

    Returns boolean

    True on success