Channel

Channel~ Channel

A class that represents the channels through which the packets travel.

Constructor

new Channel(optionsopt)

Creates a new channel.

Parameters:
Name Type Attributes Description
options Object <optional>

The options for the constructor.

Properties
Name Type Attributes Default Description
delay number <optional>
1000

The time that takes the channel to deliver the packet.

lossProb number <optional>
0

The probability between 0 and 1 to lose a packet.

damageProb number <optional>
0

The probability between 0 and 1 of damaging a packet.

Source:

Members

damageProb :number

The probability of damaging a packet.

Source:

delay :number

The time in milliseconds that takes the channel to deliver the packet.

Source:

lossProb :number

The probability of losing a packet.

Source:

Methods

damagePacket(packet) → {boolean}

Damages a packet. Does nothing if the packet is not currently traveling in this channel. If the packet is traveling and is damaged, calls onPacketDamaged() and returns true, otherwise returns false.

Parameters:
Name Type Description
packet Packet

The packet to damage.

Source:

getTravelingPackets() → {Iterator}

Returns an iterator for the current traveling packets.

Source:

losePacket(packet) → {boolean}

Loses a packet, preventing it from arriving at its receiver, and callining onPacketLost() with the packet as parameter. If the packet is not currently traveling in this channel, then it does nothing. Returns true if the packet was traveling and was stopped, and false if the packet was not traveling.

Parameters:
Name Type Description
packet Packet

The packet to lose.

Source:

onPacketDamaged(packet)

A callback that is called every time a packet is damaged.

Parameters:
Name Type Description
packet Packet

The damaged packet.

Source:

onPacketLost(packet)

A callback that is called every time a packet is lost.

Parameters:
Name Type Description
packet Packet

The lost packet.

Source:

onPacketStopped(packet)

A callback that is called when a packet is stopped.

Parameters:
Name Type Description
packet Packet

The stopped packet.

Source:

pause()

Pauses the timeouts of the current traveling packets.

Source:

resume()

Resumes the timeouts of the current traveling packets.

Source:

send(packet)

Sends a packet through the channel.

Parameters:
Name Type Description
packet Packet

The packet to send.

Source:

stop()

Stops sending the current traveling packets, preventing them from arriving at their receiver. It executes onPacketStopped() for each of the stopped packets and removes the packets from the channel.

Source: