Nebula
Transport

SimulatedNetworkTransport

An ITransport that adds the latency, jitter and packet loss of a NetworkSimulation to every link of another transport, in both directions, without touching the remote side.

generated from the sources
public sealed class SimulatedNetworkTransport : ITransport

An ITransport that adds the latency, jitter and packet loss of a NetworkSimulation to every link of another transport, in both directions, without touching the remote side. Wrap a client's transport to see how the game behaves on a slow link while the server runs on the same machine. It does not depend on LiteNetLib's debug-only simulation, so it works in the Editor and in development builds alike.

Outgoing packets are held for half the configured latency before the inner transport sends them; incoming packets are held for the other half before Poll delivers them. A request and its reply therefore take the configured latency longer, plus the link's own time. RoundTripMs adds the configured latency to the inner link's measurement, because the inner transport's own keep-alive packets never pass through the simulation. Connection and disconnection events are not delayed, so a link opens and closes at its real time. Held packets are released from Poll and Flush, so the effective resolution is how often your game calls them: once per tick.

Constructors

SimulatedNetworkTransport

public SimulatedNetworkTransport(ITransport inner, NetworkSimulation settings);

Wraps inner so its links obey settings, which can be changed while the transport runs.

Properties

Settings

public NetworkSimulation Settings { get; }

The conditions this transport applies. Change them with NetworkSimulation.Set.

DroppedPackets

public long DroppedPackets { get; }

Packets dropped by the simulated loss, or overtaken on a sequenced link, since this transport was created.

Name

public string Name { get; }

IsRunning

public bool IsRunning { get; }

LocalPort

public int LocalPort { get; }

Methods

Listen

public void Listen(int port);

StartClient

public void StartClient();

Connect

public int Connect(string host, int port);

IsConnected

public bool IsConnected(int peerId);

Disconnect

public void Disconnect(int peerId);

RoundTripMs

public int RoundTripMs(int peerId);

The inner link's round trip plus the simulated latency; -1 when the inner transport cannot measure.

Send

public void Send(int peerId, Delivery delivery, ArraySegment<byte> payload);

Poll

public void Poll(Action<TransportEvent> handler);

Flush

public void Flush();

Stop

public void Stop();

Dispose

public void Dispose();

On this page